UseOnUnmount
guarahooks/use-on-unmountFreeHook
Executes a function only once when the component is unmounted.
Install it
npx shadcn@latest add https://guarahooks.com/r/use-on-unmount.jsonSource
1'use client';23import { useEffect, useRef } from 'react';45export function useOnUnmount(callback: () => void): void {6 const fnRef = useRef(callback);78 fnRef.current = callback;910 useEffect(() => {11 return () => {12 fnRef.current();13 };14 }, []);15}
Files it writes
More from guarahooks
All 100 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| UseAbortControlleruse-abort-controller | guarahooks | Hooks | Free | no deps | |
| UseArrayStateuse-array-state | guarahooks | Hooks | Free | no deps | |
| UseAxiosuse-axios | guarahooks | Hooks | Free | no deps | |
| UseBatteryStatususe-battery-status | guarahooks | Hooks | Free | no deps | |
| UseBetterAuthuse-better-auth | guarahooks | Hooks | Free | no deps | |
| UseClickOutsideuse-click-outside | guarahooks | Hooks | Free | no deps | |
| UseConfirmuse-confirm | guarahooks | Hooks | Free | no deps | |
| UseCookieuse-cookie | guarahooks | Hooks | Free | no deps |
