thunk 심화

λ°•μ„œν˜„Β·2023λ…„ 9μ›” 14일
0
post-custom-banner

κΈ°λ³Έ μ½”λ“œ

πŸ“ index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { Provider } from 'react-redux';
import store from './redux/config/configStore';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <Provider store={store}>
    <App />
  </Provider>
);

reportWebVitals();

πŸ“ App.jsx

import React from 'react'

const App = () => {
  return (
    <div>Thunk App</div>
  )
}

export default App

πŸ“ redux / config / configstore.js

import todos from "../modules/todosSlice";
import { configureStore } from "@reduxjs/toolkit";

const store = configureStore({
  reducer: {
    todos,
  },
});

export default store;

πŸ“ redux / modules / todosSlice.js

import { createSlice } from "@reduxjs/toolkit";

const initialState = {
  todos: [],
}

export const todosSlice = createSlice({
  name: "todos",
  initialState,
  reducers: {}
})

export const {} = todosSlice.actions;
export default todosSlice.reducer;

πŸ“ db.json

{
  "todos": []
}



μˆœμ„œ

  1. trunkν•¨μˆ˜ κ΅¬ν˜„
  2. λ¦¬λ“€μ„œ 둜직 κ΅¬ν˜„ : reducers -> extraReducers
  • tjqj xhdtls : 100% 성곡(x)
  • μ§€κΈˆκΉŒμ§€μ˜ redux state(todos, counter)
  • μ•žμœΌλ‘œμ˜ state(isLoading, isError, data)
  1. κΈ°λŠ₯ 확인(network) + devTools
  2. Store의 값을 쑰회 + 화면에 λ Œλ”λ§
post-custom-banner

0개의 λŒ“κΈ€