Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Navigation re-render previous page when going back

Whats the best way to refresh the previous page when going back using Stack Navigator. No life cycle hooks seems to be triggered on the page i am returning to. I'm just using the basic example and this.props.navigation.goBack()

like image 308
Aidan Doherty Avatar asked Aug 23 '17 10:08

Aidan Doherty


People also ask

How do I go back to previous screen in React navigation?

You can go back to an existing screen in the stack with navigation. navigate('RouteName') , and you can go back to the first screen in the stack with navigation.

How do you prevent user from going back to previous page React Native?

To make this work, you need to: Disable the swipe gesture for the screen ( gestureEnabled: false ). Override the native back button in the header with a custom back button ( headerLeft: (props) => <CustomBackButton {... props} /> ).


1 Answers

You can use addListener for this

componentDidMount() {

    this.props.navigation.addListener(
      'didFocus',
      payload => {
        this.forceUpdate();
      }
    );

}
like image 73
Mahdi Bashirpour Avatar answered Oct 05 '22 01:10

Mahdi Bashirpour