【发布时间】:2019-02-21 23:10:06
【问题描述】:
//offline.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;
我有两个屏幕summary 和login,其中login 屏幕将默认呈现。但是我添加了这个逻辑this.store.getState().auth.loggedIn 来检查它是否为真,然后将屏幕发送到summary 但我得到Cannot read property 'dispatch' of undefined
【问题讨论】:
标签: reactjs react-native react-redux react-navigation redux-offline