Detect screen App

I have a app, it contains many screen and I want to detect current screen when I change state app.
I use AppState to catch event change active and inactive app.

In React Navigation v5, use useIsFocused to determine if a screen is in focus:

v4 and earlier, you’ll want withNavigationFocus:

Heads-up that there’s a nasty nasty bug with this in react-navigation 4.x that you’ll have to work around:

Anyway, our app uses withNavigationFocus to check if the screen is focused after the AppState listener is called when the app becomes active to determine if we should refresh that screen, and it works well (notwithstanding the bug).

1 Like

I didn’t know I needed this!

1 Like