Fix report dialog flashing error state on open (#10099)
(cherry picked from commit f08bf5fef9)
This commit is contained in:
committed by
Eric Bailey
parent
35dd2407ed
commit
28f4de5429
@@ -1,15 +1,14 @@
|
||||
import {useEffect, useState} from 'react'
|
||||
|
||||
export function useDelayedLoading(delay: number, initialState: boolean = true) {
|
||||
const [isLoading, setIsLoading] = useState(initialState)
|
||||
export function useDelayedLoading(delay: number, isActuallyLoading: boolean) {
|
||||
const [isDelayActive, setIsDelayActive] = useState(isActuallyLoading)
|
||||
|
||||
useEffect(() => {
|
||||
let timeout: NodeJS.Timeout
|
||||
// on initial load, show a loading spinner for a hot sec to prevent flash
|
||||
if (isLoading) timeout = setTimeout(() => setIsLoading(false), delay)
|
||||
if (!isDelayActive) return
|
||||
|
||||
return () => timeout && clearTimeout(timeout)
|
||||
}, [isLoading, delay])
|
||||
const timeout = setTimeout(() => setIsDelayActive(false), delay)
|
||||
return () => clearTimeout(timeout)
|
||||
}, [isDelayActive, delay])
|
||||
|
||||
return isLoading
|
||||
return isDelayActive || isActuallyLoading
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user