useDidUpdate
Effect that skips first render.
Import
TypeScript
import { useDidUpdate } from '@/hooks';API
Signature
useDidUpdate(effect, deps?)
When to use
Use useDidUpdate instead of re-implementing the same pattern in multiple components.
SSR / Next.js
Browser utilities are SSR-gated; lifecycle hooks are safe.
Live playground
Edit the example and see it run against the real @/hooks package in this app.
Live playgroundEdit · run with real
@/hooks · useDidUpdateEditor
function Watch({ id }: { id: string }) { useDidUpdate(() => { console.log('id changed', id); }, [id]); return null; }
Preview
Implementation source
Full library source for useDidUpdate — copy into your project when you are not installing a package yet.
hooks/utility/useDidUpdate.ts
import type { DependencyList, EffectCallback } from 'react';
import { useUpdateEffect } from './useUpdateEffect';
/** Alias for update-only effects. */
export function useDidUpdate(
effect: EffectCallback,
deps?: DependencyList,
): void {
useUpdateEffect(effect, deps);
}
Copy-paste example
useDidUpdate.example.tsx
'use client';
import { useDidUpdate } from '@/hooks';
export function Watch({ id }: { id: string }) {
useDidUpdate(() => {
console.log('id changed', id);
}, [id]);
return null;
}Production checklist
- Called only from Client Components or other custom hooks
- Type parameters filled in (e.g.
useFetch<User[]>) - Tip: Lifecycle hooks are for side effects only — not for deriving render state.
- Source of truth: open
hooks/utility/useDidUpdate.tsfor implementation details