Javascript PersistGate导致应用程序停止渲染
我正在使用Redux store和Javascript PersistGate导致应用程序停止渲染,javascript,reactjs,react-native,redux,redux-persist,Javascript,Reactjs,React Native,Redux,Redux Persist,我正在使用Redux store和PersistGate配置React本机应用程序。Redux应用商店已按预期配置和工作,但PersistGate会导致应用程序即使在第一个屏幕上也停止渲染。如果没有PersistGate,应用程序将呈现良好效果 下面是App.js代码: import React, {Component} from 'react'; import { Provider } from 'react-redux'; import { createStore,
PersistGate
配置React本机应用程序。Redux应用商店已按预期配置和工作,但PersistGate
会导致应用程序即使在第一个屏幕上也停止渲染。如果没有PersistGate
,应用程序将呈现良好效果
下面是App.js
代码:
import React, {Component} from 'react';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { persistStore, autoRehydrate } from 'redux-persist';
import { PersistGate } from 'redux-persist/integration/react';
import AppNavigator from './AppNavigator';
import SplashScreen from 'react-native-splash-screen';
import allReducers from './store/reducers/index';
const store = createStore(
allReducers,
applyMiddleware(thunk),
//compose(applyMiddleware(thunk), autoRehydrate()),
);
// This line makes store persistent.
const persistor = persistStore(store);
type Props = {};
export default class App extends Component<Props> {
componentDidMount() {
if (SplashScreen) {
SplashScreen.hide();
}
}
render() {
return (
<Provider store={ store }>
<PersistGate persistor={persistor}>
<AppNavigator />
</PersistGate>
</Provider>
);
}
}
如果我从App.js
文件中删除
标记,应用程序工作正常。但是当我使用PersistGate
时,我只看到一个白色屏幕,没有任何崩溃
我遗漏了什么导致这种奇怪的输出?您还需要调用persistReducer函数:
const persistConfig = {
key: 'root',
storage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
let store = createStore(persistedReducer)
let persistor = persistStore(store)
他们文档中的更多信息:这很有效,但商店在重新加载后仍然会丢失值。也许检查persistConfig存储选项,我从来没有在React Native中这样做过,只有在React中
const persistConfig = {
key: 'root',
storage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
let store = createStore(persistedReducer)
let persistor = persistStore(store)