useUnmount
Run the latest committed callback when an effect is cleaned up.
Keeps a fresh callback without recreating the subscription. Runs during unmount and React Strict Mode effect probes; callbacks must tolerate repeated setup/cleanup.
Usage
Examples
Playground
API
1 option
1 return value
Accessibility
Do not announce routine cleanup or steal focus. Restore focus through the owning overlay component.
Notes
- For resource acquisition, prefer a normal effect that returns the cleanup for that exact resource.
Related
useBooleanGeneric boolean state with stable toggle, enable and disable actions.useControllableStateState that works controlled or uncontrolled, like native inputs.useCountdownA pausable countdown or count-up that stops at its target.useCounterA number with increment, decrement, set and reset actions.useDebounceCallbackA debounced function with cancel and flush.useDebounceValueA value that updates only after it stops changing.