File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,14 +19,18 @@ export default function useDelayState<T>(
1919 defaultValue : T | ( ( ) => T ) ,
2020) : [ T , SetDelayState < T > ] {
2121 const [ value , setValue ] = React . useState ( defaultValue ) ;
22- const rafRef = React . useRef < number > ( null ) ;
23- const timeoutRef = React . useRef < ReturnType < typeof setTimeout > > ( null ) ;
22+ const rafRef = React . useRef < number | null > ( null ) ;
23+ const timeoutRef = React . useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
2424
2525 const cancelPending = useEvent ( ( ) => {
26- raf . cancel ( rafRef . current ! ) ;
27- clearTimeout ( timeoutRef . current ! ) ;
28- rafRef . current = null ;
29- timeoutRef . current = null ;
26+ if ( rafRef . current !== null ) {
27+ raf . cancel ( rafRef . current ) ;
28+ rafRef . current = null ;
29+ }
30+ if ( timeoutRef . current !== null ) {
31+ clearTimeout ( timeoutRef . current ) ;
32+ timeoutRef . current = null ;
33+ }
3034 } ) ;
3135
3236 const setDelayValue = useEvent < SetDelayState < T > > (
You can’t perform that action at this time.
0 commit comments