An ATproto social media client -- with an independent Appview.
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}