useUnmountedRef
Returns a read-only ref whose current value is true after the component has unmounted.
Loading preview...
The useUnmountedRef hook returns a Readonly<RefObject<boolean>> whose .current property is false while the component is mounted and true after it unmounts.
Installation
Usage
Examples
Guarding Async Callbacks After Unmount
Check unmountedRef.current after an await boundary before calling state setters or side effects.
Stopping Polling Loops When Unmounted
Break out of a recursive polling loop as soon as unmountedRef.current becomes true.