(delayMs: number)
| 7 | * @returns Whether to show the loading state |
| 8 | */ |
| 9 | export function useLoadingState(delayMs: number) { |
| 10 | const { enableArtificialDelay, isLoadingOverride } = useDebug(); |
| 11 | const [isLoading, setIsLoading] = useState(enableArtificialDelay); |
| 12 | |
| 13 | useEffect(() => { |
| 14 | if (!enableArtificialDelay) { |
| 15 | setIsLoading(false); |
| 16 | return; |
| 17 | } |
| 18 | const timer = setTimeout(() => { |
| 19 | setIsLoading(false); |
| 20 | }, delayMs); |
| 21 | return () => clearTimeout(timer); |
| 22 | }, [enableArtificialDelay, delayMs]); |
| 23 | |
| 24 | return isLoadingOverride ?? isLoading; |
| 25 | } |
no test coverage detected