Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which life cycle method will be called when returning from another page in react native?

I have a page A, then navigate to page B, then go back. I want to know which life cycle method will be called on A, or event will be emitted?

like image 692
Rocky Avatar asked Dec 11 '25 07:12

Rocky


1 Answers

When using react-navigation, you can subscribe to the didFocus and didBlur events to be notified when the user navigates to or from a screen.

You can set these up in your component's componentDidMount using the addListener method of this.props.navigation like this:

componentDidMount() {
    this.props.navigation.addListener("didFocus", () => {
        // user has navigated to this screen
    });

    this.props.navigation.addListener("didBlur", () => {
        // user has navigated away from this screen
    });
}
like image 72
Myk Willis Avatar answered Dec 14 '25 04:12

Myk Willis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!