TypeError: Cannot destructure property ‘modal' of '(0 , react_reduxWEBPACK_IMPORTED_MODULE_3.useSelector)(...)' as it is undefined
redux-toolkit 사용 중에 useSelector로 state를 받아오는 과정에서 발생한 에러
//modalSlice.jsx
...
export const modalState = (state) => state.modal;
//Header.jsx
const { isLoginOpen, isLoginWithEmailOpen, isSignupOpen } =
useSelector(modalState);
...
console에 modalState를 찍어봐도 undefined라고 떴었다.
modalState를 export했으니까 갖다 쓰면 된다고 생각했는데 store에 모듈 연결을 안했었다.
그래서 undefined라 destructure 못한다고 오류난듯
스토어에 저장했는지 확인, 또는 이름이 중복되진 않은지, 정확한지 확인하면 된다.
//store.jsx
export const store = configureStore({
reducer: { modal: modalSlice, bookmark: bookmarkSlice, auth: authSlice },
});
작년에 했던 건데 시간 없으니까 이해고 뭐고 일단 무작정 따라했나보다.
그러니까 이런 오류가 나지..