添加redux-persist后打开应用程序后,白色闪烁并出现白色死屏

时间:2019-06-25 08:19:40

标签: react-native redux redux-persist

添加redux-persist后,第二次打开该应用程序后,我出现白色闪烁并死机。 “ redux-persist”的版本为“ ^ 5.10.0”。

这是我的App.js文件:

    import { PersistGate } from 'redux-persist/integration/react'
    import {store, persistor } from './redux/store'

    export default class App extends React.Component {

  renderLoading = ()=> {
    <View>
      <ActivityIndicator size="large"/>
    </View>  
  }

      render() {
        return( 
          <Provider store={store}>
            <PersistGate loading={this.renderLoading()} persistor={persistor}>
              <AppContainer/>
            </PersistGate>
          </Provider>
        )  
      }
    }

这是我的./redux/store文件:

import { createStore, applyMiddleware } from 'redux'
import { AsyncStorage } from 'react-native'
import thunkMiddleware from 'redux-thunk'
import { persistStore, persistReducer } from "redux-persist"
import reducers from './index';

import bindAuthEvents from '../auth/redux/bindEvents';
import bindTrackingEvents from '../tracking/redux/bindEvents';

const persistConfig = {
    key: 'root',
    storage: AsyncStorage,
  }

const persistedReducer = persistReducer(persistConfig, reducers)

const createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore);

export const store = createStoreWithMiddleware(persistedReducer);

const dispatch = event => store.dispatch(event) 
const getState = () => store.getState()

bindAuthEvents(dispatch, getState);
bindTrackingEvents(dispatch, getState);

export const persistor = persistStore(store);

可能是什么问题?以及如何解决?

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,但是我使用加载组件解决了。

它最终会在模拟器中发生,但在物理设备中不会发生。