Reputation: 49
I need to navigate in redux-action. I'm try to implement an exit from an application. I always used react-native-router-flux before and not very familiar with react-navigation.
My code:
export const signOut = () => {
const nav = NavigationActions.navigate({
routeName: 'mainFlow', // It's navigation from drawer, so maybe I // don't need to specify this routeName?
action: NavigationActions.navigate({ routeName: 'intro' })
});
return () => {
try {
AsyncStorage.clear();
} finally {
AsyncStorage.getItem('token').then(function (response) {
console.log(response);
});
return nav;
}
}
};
Upvotes: 0
Views: 954
Reputation: 3805
Redux doesn't have access to navigation, But what you can do is. For example you have an action in your component...
componentDidMount() {
this.props.getData();
}
and this actions needs to access navigation. What you can do is, pass the navigation to it.
this.props.getData(this.props.navigation);
and in your getData action, you can just use the navigation object, for example
const getData =(navigation) => {
navigation.navigate('ToYourScreen');
...
}
Upvotes: 4