mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react' 2 3export function useDelayedLoading(delay: number, initialState: boolean = true) { 4 const [isLoading, setIsLoading] = React.useState(initialState) 5 6 React.useEffect(() => { 7 let timeout: NodeJS.Timeout 8 // on initial load, show a loading spinner for a hot sec to prevent flash 9 if (isLoading) timeout = setTimeout(() => setIsLoading(false), delay) 10 11 return () => timeout && clearTimeout(timeout) 12 }, [isLoading, delay]) 13 14 return isLoading 15}