【发布时间】:2019-06-28 05:24:41
【问题描述】:
我正在使用 Redux 商店和 PersistGate 配置 React Native 应用程序。 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>
);
}
}
Reducer 索引文件:
import {combineReducers} from 'redux';
import userReducer from './UserReducer';
const allReducers= combineReducers({
user: userReducer,
});
export default allReducers;
如果我从 App.js 文件中删除 <PersistGate persistor={persistor}> 标记,则应用程序可以正常工作。但是当我使用PersistGate 时,我只看到一个白屏,没有任何崩溃。
我错过了什么导致这个奇怪的输出?
【问题讨论】:
标签: javascript reactjs react-native redux redux-persist