Skip to content

Commit 70e3d47

Browse files
authored
docs: Improve readability of useRefreshOnFocus (#3465)
1 parent b992f89 commit 70e3d47

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

docs/src/pages/react-native.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,19 @@ import React from 'react'
5555
import { useFocusEffect } from '@react-navigation/native'
5656

5757
export function useRefreshOnFocus<T>(refetch: () => Promise<T>) {
58-
const enabledRef = React.useRef(false)
58+
const firstTimeRef = React.useRef(true)
5959

6060
useFocusEffect(
6161
React.useCallback(() => {
62-
if (enabledRef.current) {
63-
refetch()
64-
} else {
65-
enabledRef.current = true
62+
if (firstTimeRef.current) {
63+
firstTimeRef.current = false;
64+
return;
6665
}
66+
67+
refetch()
6768
}, [refetch])
6869
)
6970
}
7071
```
72+
73+
In the above code, `refetch` is skipped the first time because `useFocusEffect` calls our callback on mount in addition to screen focus.

0 commit comments

Comments
 (0)