본문 바로가기
반응형

Redux3

[React] React에서 persist사용하기 (react-persist) 우선 persist는 redux를 사용할 때 새로고침을 해도 데이터를 유지하기 위해서 사용되는데 사용하기 위해서는 아래와 같이 우선 설치부터 시작해주자 ! yarn add react-persist 설치를 한 후엔 우선 redux의 store를 만들어준 부분에 가서 아래와 같이 만들어 준다. import { configureStore } from "@reduxjs/toolkit"; import storage from "redux-persist/lib/storage/session"; import { combineReducers } from "@reduxjs/toolkit"; import { persistReducer } from "redux-persist"; ... const persistConfig = {.. 2022. 6. 10.
[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.
[Next.js] Next.js + Redux + TypeScript 사용중 state값 proxy로 나올때 해결법 import { current } from '@reduxjs/toolkit' ... extraReducers: (builder) => { builder.addCase(logIn.fulfilled, (state, action) => { console.log(current(state)) }); }, console.log(state)했을 때 proxy값으로 나오면 import {current} 해서 아래처럼 입력해주면 값이 제대로 나온다. 2022. 2. 17.