yarn add redux react-redux
src/redux/config/configStore.js
src/redux/modules
import { createStore, combineReducers } from 'redux';
import FanLetterReducer from 'redux/modules/FanLetter';
const rootReducer = combineReducers({
// 생성한 module 넣기
FanLetterReducer
});
const store = createStore(rootReducer);
export default store;
import FakeData from '../FakeData.json';
const initialState = FakeData;
const FanLetterReducer = (state = initialState, action) => {
switch (action.type) {
default:
return state;
}
};
export default FanLetterReducer;
// index.js
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>
);
import { useSelector } from 'react-redux';
const Router = () => {
const data = useSelector((state) => {
return state;
});
console.log(data);
return (
<BrowserRouter>
(...)
</BrowserRouter>
);
};
export default Router;