useUpdateEffect
Alias of useDidUpdate pattern.
Import
TypeScript
import { useUpdateEffect } from '@/hooks';API
Signature
useUpdateEffect(effect, deps?)
When to use
Use useUpdateEffect 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 · useUpdateEffectEditor
function AfterMount({ q }: { q: string }) { useUpdateEffect(() => { console.log('search', q); }, [q]); return null; }
Preview
Implementation source
Full library source for useUpdateEffect — copy into your project when you are not installing a package yet.
hooks/utility/useUpdateEffect.ts
import { useEffect, type DependencyList, type EffectCallback } from 'react';
import { useFirstMountState } from './useFirstMountState';
/** useEffect that skips the initial mount. */
export function useUpdateEffect(
effect: EffectCallback,
deps?: DependencyList,
): void {
const isFirst = useFirstMountState();
useEffect(() => {
if (isFirst) return;
return effect();
}, deps);
}
Copy-paste example
useUpdateEffect.example.tsx
'use client';
import { useUpdateEffect } from '@/hooks';
export function AfterMount({ q }: { q: string }) {
useUpdateEffect(() => {
console.log('search', q);
}, [q]);
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/useUpdateEffect.tsfor implementation details