Files
bsky-social-app/src/components/hooks/useRefreshOnFocus.ts
T
2024-05-03 17:57:20 +01:00

18 lines
380 B
TypeScript

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]),
)
}