react native navigation goback with params

Solutions on MaxInterview for react native navigation goback with params by the best coders in the world

showing results for - "react native navigation goback with params"
Luca
24 Oct 2020
1You can pass a callback function as parameter when you call navigate like this:
2
3  const DEMO_TOKEN = await AsyncStorage.getItem('id_token');
4  if (DEMO_TOKEN === null) {
5    this.props.navigation.navigate('Login', {
6      onGoBack: () => this.refresh(),
7    });
8    return -3;
9  } else {
10    this.doSomething();
11  }
12And define your callback function:
13
14refresh() {
15  this.doSomething();
16}
17Then in the login/registration view, before goBack, you can do this:
18
19await AsyncStorage.setItem('id_token', myId);
20this.props.navigation.state.params.onGoBack();
21this.props.navigation.goBack();
22Update for React Navigation v5:
23
24await AsyncStorage.setItem('id_token', myId);
25this.props.route.params.onGoBack();
26this.props.navigation.goBack();