add focus refresh + polling (#3846)
This commit is contained in:
parent
4a2d4253e5
commit
ce02a41163
3 changed files with 23 additions and 2 deletions
17
src/components/hooks/useRefreshOnFocus.ts
Normal file
17
src/components/hooks/useRefreshOnFocus.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import {useCallback, useRef} from 'react'
|
||||
import {useFocusEffect} from '@react-navigation/native'
|
||||
|
||||
export function useRefreshOnFocus<T>(refetch: () => Promise<T>) {
|
||||
const firstTimeRef = useRef(true)
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
if (firstTimeRef.current) {
|
||||
firstTimeRef.current = false
|
||||
return
|
||||
}
|
||||
|
||||
refetch()
|
||||
}, [refetch]),
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue