AZ.dev

React Essentials Cheat Sheet

React

The hooks and patterns that carry most React components, from effects that clean up after themselves to keys, transitions, and lazy routes.

13 cards | react: 19

State

Keep a value across renders without re-rendering

const timer = useRef<number | null>(null);

Changing timer.current doesn’t render. Use state for anything the UI shows.

Bind an input to state

<input value={name} onChange={(e) => setName(e.target.value)} />

Effects

Skip an expensive computation when its inputs haven't changed

const sorted = useMemo(() => [...items].sort(byName), [items]);

Keep a callback's identity stable for a memoized child

const onSave = useCallback(() => save(draft), [draft]);

Only worth it when the child is wrapped in memo or the function is an effect dependency.

Composition

Give each list item a stable key

{users.map((u) => <UserRow key={u.id} user={u} />)}

The index as a key breaks as soon as the list reorders or an item is removed.

Share a value without threading it through props

const ThemeContext = createContext<Theme>("light");

const theme = useContext(ThemeContext);

Every consumer re-renders when the provider’s value changes, so keep the value small.

Type a component's children

function Card({ children }: { children: ReactNode }) {
  return <div className="card">{children}</div>;
}

Load a heavy component only when it renders

const Editor = lazy(() => import("./editor"));

<Suspense fallback={<Spinner />}>
  <Editor />
</Suspense>

The import becomes its own chunk. The fallback shows until it arrives.

Responsiveness

Keep typing smooth while a slow update runs

const [isPending, startTransition] = useTransition();

startTransition(() => setQuery(input));

The update inside the transition can be interrupted by the next keystroke. isPending is true until it lands.

Handle a form submit with an action

<form action={async (formData) => { await save(formData.get("title")); }}>

React 19 resets the form after the action resolves and tracks the pending state for useFormStatus.