fix user refresher

This commit is contained in:
john 2025-05-19 17:52:18 +02:00
parent 17c9885ccc
commit 5f47162a50
6 changed files with 85 additions and 36 deletions

17
src/hooks/useOnMounted.ts Normal file
View file

@ -0,0 +1,17 @@
import { useEffect, useRef } from 'react'
export function useOnMounted(callback: () => void | Promise<void>) {
const isMounted = useRef(false)
useEffect(() => {
if (isMounted.current) return
isMounted.current = true
const timeoutId = setTimeout(callback)
return () => {
isMounted.current = false
clearTimeout(timeoutId)
}
}, [callback])
}