Under The Hood
frontend react React Compiler (React 19)

React Compiler: automatic memoization

Last updated
Prerequisites:
React rendering model
useMemo/useCallback and memo() basics
  • react
  • compiler
  • memoization
  • performance
  • babel
  • react-compiler

Read at your depth

The practical view

Until now you manually wrapped values in useMemo and functions in useCallback, and wrapped components in memo() to skip re-renders. The React Compiler (installed as a Babel/SWC plugin, e.g. babel-plugin-react-compiler) analyzes your components and automatically applies memoization wherever it is safe: it memoizes computed values, callback functions, and JSX subtrees, so hand-written useMemo/useCallback/memo become mostly unnecessary. You keep coding normally — no new syntax — and the compiler inserts the caching. Rules of React still apply: no mutating props/state during render, hooks called unconditionally.

The same idea in other frameworks

react equivalent
// Compiler handles this:
const doubled = compute(items); // memoized automatically
const onSave = () => save(draft); // memoized automatically

Legacy vs modern

Manual useMemo/memo scaffolding vs compiler-auto memoization

Hand-written memoization is error-prone and verbose; the compiler derives the same caching automatically and stays correct as the component evolves.

before → after
Manual memoization
const list = useMemo(() => items.filter(byQuery), [items, query]);
const onPick = useCallback((id) => pick(id), []);
const Row = memo(TableRow);
Compiler memoization
const list = items.filter(byQuery);
const onPick = (id) => setSelected(id);

Interview gotchas

Under The Hood — a multi-depth technical interview hub.

Press ⌘ K to search.