fix user refresher
This commit is contained in:
parent
17c9885ccc
commit
5f47162a50
6 changed files with 85 additions and 36 deletions
17
src/hooks/useOnMounted.ts
Normal file
17
src/hooks/useOnMounted.ts
Normal 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])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue