useUnmount
Lifecycle & refsA type-safe React hook that runs a callback when a component unmounts
Install
$ npm install @usefy/use-unmountQuick start
import { useUnmount } from "@usefy/use-unmount";
function MyComponent() {
useUnmount(() => {
console.log("Component unmounted");
});
return <div>Hello</div>;
}API reference
useUnmount(callback, options?)
Executes callback when the component unmounts. Returns void.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
callback | () => void | — | Function to execute when the component unmounts |
options | UseUnmountOptions | {} | Optional configuration |
UseUnmountOptions
| Property | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Whether to run the callback on unmount, read at unmount time |
Runs only on unmount: the
enabledvalue is captured in a ref and read when the component actually unmounts. Flippingenabledfromtruetofalse(or back) while the component is still mounted never fires the callback.
Go deeper
This page is the quick reference. For every example, prop, and edge case, read the full README — or open Storybook to change props live.