【发布时间】:2019-11-07 00:49:56
【问题描述】:
在添加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);
可能是什么问题?以及如何解决?
【问题讨论】:
标签: react-native redux redux-persist