@@ -42,7 +42,7 @@ export const useDeferredTrigger = (
4242 { delay = 100 , minDuration = 400 , base = false } : IDeferredTriggerOptions = { }
4343) => {
4444 const [ deferredFlag , setDeferredFlag ] = useState ( base )
45- const timeoutRef = useRef < number > ( )
45+ const timeoutRef = useRef < ReturnType < typeof setTimeout > > ( )
4646 const lastActive = useRef < number > ( )
4747
4848 useEffect ( ( ) => {
@@ -75,15 +75,16 @@ export const useDeferredTrigger = (
7575 // We need to wait at least a certain amount of time before
7676 // applying the delay. This can always be canceled by an update
7777 // that re-triggers this effect (as the timeout can be cleared).
78- clearTimeout ( timeoutRef . current )
79- timeoutRef . current = window . setTimeout ( toggleFlag , scheduledDelay )
78+ timeoutRef . current = setTimeout ( toggleFlag , scheduledDelay )
8079 }
8180 }
8281 } else {
8382 // The target flag matches the deferred flag,
8483 // so clear any scheduled changes to it.
85- clearTimeout ( timeoutRef . current )
86- timeoutRef . current = undefined
84+ if ( timeoutRef . current !== undefined ) {
85+ clearTimeout ( timeoutRef . current )
86+ timeoutRef . current = undefined
87+ }
8788 }
8889 } , [ flag , deferredFlag , base , delay , minDuration ] )
8990
0 commit comments