UseDidUpdate
guarahooks/use-did-updateFreeHook
Executes a function when the component is updated, but not when it is mounted.
Install it
npx shadcn@latest add https://guarahooks.com/r/use-did-update.jsonSource
1'use client';23import { DependencyList, EffectCallback, useEffect, useRef } from 'react';45export function useDidUpdate(effect: EffectCallback, deps?: DependencyList) {6 const mounted = useRef(false);78 useEffect(9 () => () => {10 mounted.current = false;11 },12 [],13 );1415 useEffect(() => {16 if (mounted.current) {17 return effect();18 }1920 mounted.current = true;21 return undefined;22 }, deps);23}
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 |
