Docs
useUnmount
Run a function when a component unmounts, ensuring cleanups or final actions are handled effectively.
Installation
pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-unmount
Usage
"use client"
import { useUnmount } from "@/hooks/use-unmount"
export default function Component() {
useUnmount(() => {
// Cleanup logic here
})
return <div>Hello world</div>
}
API Reference
Parameters
Name | Type | Description | Default Value | Optional |
---|---|---|---|---|
Function | () => void | The cleanup function to be executed on unmount. | () => undefined | No |
Return Values
Type | Description |
---|---|
void | A function that runs the cleanup function when the component unmounts. |