//离线.js
import { offline } from '@redux-offline/redux-offline';
import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
const config = params => ({
...offlineConfig,
persistCallback: params.persistCallback
});
export default params => offline(config(params));
//App.js
class App extends Component {
componentWillMount() {
this.store = Reactotron.createStore(
reducers,
undefined,
compose(
applyMiddleware(ReduxThunk),
offline({ persistCallback: this.startApp })
)
);
}
startApp = () => {
if (this.store.getState().auth.loggedIn) {
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'summmary' })],
});
this.props.navigation.dispatch(resetAction);
}
}
render() {
return (
<Provider store={this.store}>
<MainNavigator />
</Provider>
);
}
}
export default App;
我有 2 个屏幕summary
,默认情况下将在login
哪里渲染屏幕。login
但是我添加了这个逻辑this.store.getState().auth.loggedIn
来检查它是否为真然后将屏幕发送到summary
但我得到了Cannot read property 'dispatch' of undefined