import {persistReducer,persistStore} from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import { PersistGate } from 'redux-persist/integration/react';
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
//redux-persist
const persistConfig = {
key:'root',
storage
}
const enhancedReducer = persistReducer(persistConfig,rootReducer)
const store = createStore(enhancedReducer, composeEnhancer(applyMiddleware(thunk)))
const persistor = persistStore(store)
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>,
document.getElementById('root')
);
하려는 것 - 페이지 새로고침 시 redux store에 있는 데이터 보존
1. npm i redux-persists
index.js
기존 index.js 에 있는 store 코드에 persists 코드를 더한다
Result