This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Handle screen focus
Edit page
Run effects, render UI, and respond to navigation events when an Expo Router screen is focused.
Expo Router provides three ways to respond when a screen gains or loses focus:
Run an effect when a screen is focused
Use useFocusEffect for work that should run only while a screen is focused, such as a subscription. Wrap the callback in useCallback so the effect does not run on every render.
srcappprofile.tsxThe callback runs when the screen comes into focus. While the screen remains focused, it also runs again if any of its dependencies change.
Return a cleanup function to stop the work when the screen loses focus, the dependencies change, or the component unmounts.
Pass dependencies to useFocusEffect
useFocusEffect accepts only one argument. Put dependencies in the useCallback dependency array:
useFocusEffect( useCallback(() => { const subscription = subscribeToProfileUpdates(profileId); return () => subscription.unsubscribe(); }, [profileId]) );
Render based on focus
Use useIsFocused when the rendered UI depends on whether the screen is focused. It returns a boolean and re-renders the component when focus changes.
Listen for focus and blur events
Prefer
useFocusEffectwhenever possible. UseuseNavigation().addListeneronly when you cannot express the work as an effect tied to screen focus.
Use useNavigation to run code for a specific focus or blur event. Subscribe in an effect and remove both listeners in its cleanup: