Detect navigation changes

1.5k Views Asked by At

I have a react native App. I'll like to detect navigation to screens, so when I navigate to a specific screen I trigger a update function. I have the componentDidMount but works only when navigating for the first time... Also have looked at AppState but do not monitor navigation between screen, how should I do it?

Thanks

1

There are 1 best solutions below

3
docmurloc On

you can use the hook useFocusEffect from react navigation.

Sometimes we want to run side-effects when a screen is focused. A side effect may involve things like adding an event listener, fetching data, updating document title, etc. While this can be achieved using focus and blur events, it's not very ergonomic.