React Hooks Cheat Sheet: useState, useEffect, useActionState and use
Checked against React React 19.3 (latest on npm: 19.3.1); this repo uses 19.2.7 on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers writing function components who want the signature and the main gotcha of each hook in one place. It follows the react.dev reference for React 19.3, the current release (19.3.1 on npm on 28 Nov 2026). Rows are docs-only because hooks need a rendered component to run.
When to use what
Reach for useState first and useReducer once several pieces of state change together or the update logic deserves its own tests. If a value can be computed from props or state, compute it during render; it does not need state or an effect.
Effects are for syncing with something outside React: a socket, a timer, a browser API, a third-party widget. If you find yourself writing an effect that sets state based on other state, delete it and compute the value instead. When an effect needs the latest value of a prop without re-running on every change, useEffectEvent is the tool for that in React 19.2 and later.
Do not sprinkle useMemo and useCallback everywhere. Use them when a calculation is measurably slow or when a stable reference matters to a memoized child or an effect's dependency list. Next.js 16 ships stable support for the React Compiler, which memoizes for you, so find out if your build already does this. Our React performance post has worked examples.
For forms, React 19's Actions remove most hand-written loading state. useActionState gives you the result and a pending flag, useFormStatus lets a submit button read its parent form, and useOptimistic shows the expected result while the request runs. The form validation patterns post and our state management overview cover when to bring in a library instead.
useReducer and useContext follow the same top-level rule as every other hook.
const [count, setCount] = useState(0)Declare a state variable and its setter
setCount(c => c + 1)Update from the previous value so batched updates do not lose increments
useState(() => expensiveInit())Pass a function so the initial value is computed only on the first render
const [state, dispatch] = useReducer(reducer, initialArg)Keep related state and its update rules in one reducer function
const theme = useContext(ThemeContext)Read the nearest provider's value and re-render when it changes
const id = useId()Stable unique ID for linking a label to an input, safe with server rendering
In development Strict Mode React runs one extra setup and cleanup cycle on mount to expose missing cleanup. Production runs setup once.
useEffect(() => { ...; return () => cleanup() }, [roomId])Connect to something outside React and undo it when roomId changes or the component unmounts
useEffect(fn, [])Run only after the first commit
useEffect(fn)No dependency array: run after every commit
const onTick = useEffectEvent(() => log(latestProp))Read the latest props inside an effect without adding them as dependencies (React 19.2+)
useLayoutEffect(fn, deps)Run before the browser paints, for measuring layout such as tooltip positions
const inputRef = useRef(null)Hold a DOM node or any mutable value that should not trigger a re-render
useImperativeHandle(ref, () => ({ focus }))Expose a limited set of methods to a parent's ref; rarely needed
useSyncExternalStore(subscribe, getSnapshot)Subscribe to a store outside React, such as a browser API or state library
State updates after an await inside startTransition need their own startTransition wrapper.
const total = useMemo(() => sum(items), [items])Cache an expensive calculation between renders until items changes
const onSave = useCallback(() => save(id), [id])Keep the same function reference for a memoized child or an effect dependency
const [isPending, startTransition] = useTransition()Mark an update as non-blocking and show a pending state while it renders
startTransition(async () => { await save(); startTransition(() => setPage('/done')) })Async transition; wrap updates after await again
const deferred = useDeferredValue(query)Let a slow list lag behind fast typing when you cannot wrap the update yourself
useFormStatus is exported from react-dom, not react (https://react.dev/reference/react-dom/hooks/useFormStatus).
const [state, formAction, isPending] = useActionState(action, initialState)Run a form action, keep its last result, and know when it is pending
async function action(prevState, formData) { ... }Action signature with useActionState: previous state first, then the FormData
const { pending, data, method } = useFormStatus()Read the parent form's submission state from a child such as a submit button
const [optimistic, addOptimistic] = useOptimistic(value, reducer)Show the expected result while an Action runs; it reverts to value when the Action ends
const data = use(promise)Read a promise during render; the component suspends until it resolves
if (show) { const t = use(ThemeContext) }use is not a hook, so it may be called inside conditions and loops
eslint-plugin-react-hooks catches most violations at edit time.
Top level onlyCall hooks at the top of a component or custom hook, before any early return
No hooks in conditions or loopsCall the hook unconditionally and branch on its result instead
No hooks in event handlersRead context or state at the top level and use the value inside the handler
No hooks inside useMemo, useReducer or useEffect callbacksMove the hook call outside and pass its result in
No hooks in try/catch/finallyWrap the risky work, not the hook call, or use an error boundary
function useOnlineStatus() { ... }Custom hooks start with use and may call other hooks
Worked example: A form with useActionState and a useFormStatus submit button
This pattern replaces a useState for the result, another for loading, and an onSubmit handler:
import { useActionState } from 'react';
import { useFormStatus } from 'react-dom';
async function subscribe(prevState, formData) {
const email = formData.get('email');
const res = await fetch('/api/subscribe', { method: 'POST', body: formData });
if (!res.ok) return { error: 'Could not subscribe ' + email };
return { error: null, done: true };
}
function SubmitButton() {
const { pending } = useFormStatus();
return <button disabled={pending}>{pending ? 'Sending...' : 'Subscribe'}</button>;
}
export default function Newsletter() {
const [state, formAction, isPending] = useActionState(subscribe, { error: null });
return (
<form action={formAction}>
<input name="email" type="email" required />
<SubmitButton />
{state.error && <p role="alert">{state.error}</p>}
{state.done && <p>Thanks, check your inbox.</p>}
</form>
);
}
When the form submits, React calls subscribe with the previous state and the form's FormData, and whatever it returns becomes the new state. The action returns an error object for expected failures instead of throwing, because a throw cancels queued actions and shows the nearest error boundary. SubmitButton sits inside the form, which is why useFormStatus can see the submission; calling it in Newsletter itself would always report pending: false. We did not run this in a browser; it follows the react.dev reference pages for both hooks.
Common mistakes
Using an effect to copy props into state or compute a filtered list.
Compute the value during render. Add
useMemoonly if the calculation is measurably slow.Creating an object or function in the component body and listing it as an effect dependency.
It changes identity every render, so the effect re-runs every time. Create it inside the effect or depend on its primitive fields.
Calling
use(fetch(url))directly in a client component.That creates a new promise each render and suspends forever. Cache the promise, or create it in a server component and pass it down.
Wrapping
usein try/catch to handle a rejected promise.usethrows to integrate with Suspense. Put an error boundary above the component instead.Calling
useFormStatusin the same component that renders the<form>.It only reads a parent form. Move the hook into a child component such as the submit button.
Calling the
useOptimisticsetter outside an Action or transition.React warns and the optimistic value flashes and disappears. Call it inside
startTransitionor a form action.
Related cheat sheets
Sources
- https://react.dev/reference/react/hooks
- https://react.dev/reference/react/useEffect
- https://react.dev/reference/react/useActionState
- https://react.dev/reference/react-dom/hooks/useFormStatus
- https://react.dev/reference/react/useOptimistic
- https://react.dev/reference/react/use
- https://react.dev/reference/react/useTransition
- https://react.dev/reference/rules/rules-of-hooks
- https://react.dev/versions
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.