0

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;
        }
    }

};

1 Answer 1

4

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');
...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.