에러
[React] history 사용하기
박헹구
2021. 10. 27. 23:32
반응형
//store.js
import { configureStore } from "@reduxjs/toolkit";
import { connectRouter, } from "connected-react-router";
import {history} from "./history";
export const store = configureStore({
reducer: {
router: connectRouter(history),
},
});
//history.js
import { createBrowserHistory } from 'history'
export const history = createBrowserHistory();
히스토리를 그냥 store에 넣고 돌리면
초기화 하라는 미친듯한 에러가 뜨던가 라우터에서 값이 확인이 안될 때가 많다.
ReferenceError: Cannot access ''data" before initialization react 이거나
라우터에서 다른 reducer를 찾지 못한다는 미친듯한 에러가 난다.
저렇게 따로 빼주면 에러 다 해결!!!!!!!!!!
반응형