diff --git a/docs/src/pages/react-native.md b/docs/src/pages/react-native.md index e0e9f46e8a..ce814c4c74 100644 --- a/docs/src/pages/react-native.md +++ b/docs/src/pages/react-native.md @@ -55,16 +55,19 @@ import React from 'react' import { useFocusEffect } from '@react-navigation/native' export function useRefreshOnFocus(refetch: () => Promise) { - const enabledRef = React.useRef(false) + const firstTimeRef = React.useRef(true) useFocusEffect( React.useCallback(() => { - if (enabledRef.current) { - refetch() - } else { - enabledRef.current = true + if (firstTimeRef.current) { + firstTimeRef.current = false; + return; } + + refetch() }, [refetch]) ) } ``` + +In the above code, `refetch` is skipped the first time because `useFocusEffect` calls our callback on mount in addition to screen focus.