본문 바로가기
반응형

RTK3

[RTK] Redux Toolkit 사용할 때 state값 proxy로 나올 때 해결법 RTK를 사용할 때 state값이 proxy로 나온다면 import { createSlice, current } from "@reduxjs/toolkit"; ... console.log(current(state.data)); current를 붙여서 확인하면 데이터가 제대로 나온다. https://stackoverflow.com/questions/64586207/redux-toolkit-state-showing-as-proxy-undefined-within-reducer Redux Toolkit: state showing as Proxy / undefined within reducer Solved it, thanks! - For anyone interested, I was trying to access s.. 2022. 5. 29.
[Next.js] Next.js에서 redux-persist 사용 새로고침하면 리덕스가 초기화 되는 걸 해결하기 위해서 redux-persist를 사용해서 새로고침해도 리덕스가 초기화 되는 현상을 막아주었다. 우선 redux-persist 모듈을 깔아주고. 아래와 같이 설정해주었다. yarn add redux-persist or npm install redux-persist //persistMiddleware.ts import { REHYDRATE } from 'redux-persist/lib/constants'; import { Middleware } from 'redux'; const persistMiddleware: Middleware = (store) => (dispatch) => async ( action, ) => { if (action.type === RE.. 2022. 2. 24.
[React] history 사용하기 //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에 넣고 돌리면 초기화 하라는 미친듯한 에러가 뜨던가 라우터에서.. 2021. 10. 27.