wwwwwwwwwwwwwwwwwww

useFocusEffect

Similar to React useEffect, but only runs when the current route is focused. This is directly based off React Navigation's useFocusEffect.

You must pass it an array as the second argument to determine memoization, otherwise the effect will not change.

Example:

import { useFocusEffect } from '@react-navigation/native'
import { useCallback } from 'react'
function Profile({ userId }) {
const [user, setUser] = React.useState(null)
useFocusEffect(
() => {
const unsubscribe = API.subscribe(userId, (user) => setUser(user))
return () => unsubscribe()
},
[userId]
)
return <ProfileContent user={user} />
}

Edit this page on GitHub.