mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useCallback, useRef} from 'react'
2import {useFocusEffect} from '@react-navigation/native'
3
4export function useRefreshOnFocus<T>(refetch: () => Promise<T>) {
5 const firstTimeRef = useRef(true)
6
7 useFocusEffect(
8 useCallback(() => {
9 if (firstTimeRef.current) {
10 firstTimeRef.current = false
11 return
12 }
13
14 refetch()
15 }, [refetch]),
16 )
17}