I have store config.autologin properties with Redux-persist. When I create a React-navigation stack, I'd like to check autoloign value, but at this time the state isn't rehydrated yet. I supposed that PersistGate is what I need, but this ins't true. Can you help me? Thanks
App.js
export default class App extends React.Component {
render() {
return (
<Provider store={reduxStore}>
<PersistGate loading={null} persistor = {persistor}>
<AppContainer
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
</PersistGate>
</Provider>
);
}
}
reduxStore
const persistState = {
key: 'root',
storage,
whitelist: ['config']
}
const persistedReducer = persistReducer(persistState, reducers)
export const reduxStore = createStore(persistedReducer, devToolsEnhancer({ realtime: true }))
export const persistor = persistStore(reduxStore)
AppNavigation
selectInitialRoute = () =>{
if(reduxStore.getState().config.autoLogin)
return 'DrawerStack'
else
return 'Home'
}
const defaultNavigation = createStackNavigator({
Home: loginNavigation,
DrawerStack: defaultDrawerNavigation
}, {
initialRouteName: this.selectInitialRoute(),
defaultNavigationOptions: {
header: null
},
}
)
const AppContainer = createAppContainer(defaultNavigation);
export default AppContainer