15 lines
431 B
TypeScript
15 lines
431 B
TypeScript
import {useEffect, useState} from 'react'
|
|
|
|
export function useDelayedLoading(delay: number, isActuallyLoading: boolean) {
|
|
const [isDelayActive, setIsDelayActive] = useState(isActuallyLoading)
|
|
|
|
useEffect(() => {
|
|
if (!isDelayActive) return
|
|
|
|
const timeout = setTimeout(() => setIsDelayActive(false), delay)
|
|
return () => clearTimeout(timeout)
|
|
}, [isDelayActive, delay])
|
|
|
|
return isDelayActive || isActuallyLoading
|
|
}
|