[英]How can I preserve my redux (redux-saga) data without display/store in local or session storage on page load?
Please checkout the below files where is setup my redux store.请查看以下文件,其中设置了我的 redux 商店。
configureStore.js file configureStore.js 文件
export default function configureStore(initialState) {
const sagaMiddleware = createSagaMiddleware()
const composeEnhancers =
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const logger = store => next => action => {
let result = next(action)
try {
const fullState = store.getState()
localStorage.setItem("state", JSON.stringify(fullState));
} catch (e) {
console.error("localStorage set error:", e)
}
return result
}
const store = createStore(
rootReducer,
initialState,
composeEnhancers(applyMiddleware(sagaMiddleware, logger))
)
sagaMiddleware.run(rootSaga)
return store
}
Please check the root index.js file where I want to restore my redux info on application load请检查我要在其中恢复我的 redux 应用程序加载信息的根index.js文件
let initialState = {}
try {
// set redux data in initial state
initialState = JSON.parse(localStorage.getItem("state")) || {};
} catch (e) {
console.error("localStorage get error:", e)
}
const store = configureStore(initialState)
const app = (
<Provider store={store}>
<BrowserRouter>
<App />
<Loader />
</BrowserRouter>
</Provider>
)
Please help me out from this problem.请帮我解决这个问题。 Thanks in advance提前致谢
I think you can try out redux-persist for this.我认为您可以为此尝试 redux-persist 。
https://blog.reactnativecoach.com/the-definitive-guide-to-redux-persist-84738167975 https://blog.reactnativecoach.com/the-definitive-guide-to-redux-persist-84738167975
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.