StateBeginnerFully SSR-safehooks/state/useUpdate.ts

useUpdate

Force a re-render from anywhere in the component.

Import

TypeScript
import { useUpdate } from '@/hooks';

API

Signature

useUpdate() → () => void

When to use

Use useUpdate instead of re-implementing the same pattern in multiple components.

SSR / Next.js

Fully SSR-safe. Pure React state.

Live playground

Edit the example and see it run against the real @/hooks package in this app.

Live playgroundEdit · run with real @/hooks · useUpdate
Editor
function ForceRender() {
  const update = useUpdate();
  return <button onClick={update}>Re-render now</button>;
}
Preview

Implementation source

Full library source for useUpdate — copy into your project when you are not installing a package yet.

hooks/state/useUpdate.ts
export { useUpdate } from '../utility/useUpdate';

Copy-paste example

useUpdate.example.tsx
'use client';

import { useUpdate } from '@/hooks';

export function ForceRender() {
  const update = useUpdate();
  return <button onClick={update}>Re-render now</button>;
}

Production checklist

  • Called only from Client Components or other custom hooks
  • Type parameters filled in (e.g. useFetch<User[]>)
  • Tip: Keep state setters stable; prefer action helpers over manual setState spreads.
  • Source of truth: open hooks/state/useUpdate.ts for implementation details