我是redux-persist的新手,但我认为自己走对了。找到一些文档后,我在persistStore
中实现了store.js
。但是,启动网页时,@@ INIT,restore / PERSIST和persist / REHYDRATE将显示在redux检查器中。在最后一步中,甚至将_persist.rehydrated从false设置为true,但我的网页仍然显示“ LOADING”,如loading
的{{1}}属性所给。浏览器的控制台日志中没有显示其他错误。
有人对为何不加载PersistGate
有何建议?
store.js
DashboardComponent
App.js
import { createStore, compose, applyMiddleware } from "redux"
import createSagaMiddleware from "redux-saga"
import { persistStore, persistCombineReducers } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
//import myReducer from "./ducks/reducers"
import mySaga from "./sagas/sagas"
import websocket from "./ducks/websocket"
import dds from "./ducks/dds"
import dashboard from "./ducks/dashboard"
const reducers = {
dashboard,
websocket,
dds,
};
const rootReducer = persistCombineReducers({
key: 'root',
storage,
}, reducers);
const middlewares = []
const enhancers = []
const sagaMiddleware = createSagaMiddleware()
middlewares.push(sagaMiddleware);
enhancers.push(applyMiddleware(...middlewares));
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
export const store = createStore(
rootReducer,
composeEnhancers(...enhancers),
);
export const persistor = persistStore(store);
sagaMiddleware.run(mySaga);
export default store
编辑:
import React from "react"
import { Provider } from "react-redux"
import { PersistGate } from 'redux-persist/integration/react'
import persistor from "./store"
import "./App.css"
import DashboardComponent from "./containers/dashboard/dashboard_component"
import store from "./store"
export default () => (
<Provider store={store}>
<PersistGate loading={'LOADING'} persistor={persistor}>
<DashboardComponent />
</PersistGate>
</Provider>
)
组件的状态具有成员PersistGate
。当bootstrapped
为bootstrapped
时,true
的子代将被渲染。当我手动将PersistGate
的状态检查为bootstrapped
时,将呈现true
,但仍然没有应有的全部功能。所以问题是,为什么在执行persist / REHYDRATE步骤时DashboardComponent
为什么不成立?