← Back to React, page 3

react-0043 · Hard senior

What does the React Compiler do, what are its limits, and how does it change the way you use memo, useMemo and useCallback?

React Compiler is a build-time tool, a Babel plugin, that analyzes components and hooks and adds memoization automatically, skipping work when inputs have not changed. It assumes your code follows the Rules of React: pure render, no mutation of props or state. You write plain components and the compiler caches values, functions and JSX. Manual memo hooks are still useful as an escape hatch and for precise control over effect dependencies.

Full answer

Manual memoization is tedious and easy to get wrong. A missing dependency causes a stale value, and a forgotten useCallback causes needless re-renders. React Compiler 1.0, stable since October 2025, does this analysis for you at build time.

It reads each component and hook, builds a model of which values depend on which inputs, and rewrites the function so that each piece of the output is cached and reused when its inputs are unchanged. The compiled code keeps a small cache array, created with a function imported from react/compiler-runtime, and compares inputs with Object.is. It can memoize things hooks cannot, such as values after a conditional return, and the JSX of unchanged branches. As a result, a child component receives the same element and React skips it, even without memo.

It works only when the code follows the Rules of React. It does not change behaviour for correct code. For code that mutates props, reads and writes refs during render, or otherwise breaks the rules, the compiler skips that component, and the bundled ESLint rules report why. You can opt in per file with the "use memo" directive or opt out with "use no memo" while debugging. Teams usually adopt it gradually, with the compilationMode: 'annotation' option or by directory.

What changes for you? Stop adding useMemo and useCallback for performance by default. Keep them where you need a guaranteed stable reference, such as an effect dependency or a value passed to a non-React library, and keep React.memo for expensive children when you want an explicit contract. Existing manual memoization is safe to leave.

The compiler needs a build step: the Babel plugin, or the Vite, Next.js and other integrations. It does not fix slow algorithms, giant lists, waterfalls or bad data fetching, so profiling still matters.

The example below was compiled and run twice, once plain and once with the compiler, and the render counts were compared.

jsx
import { useState } from 'react';

function Roster({ names }) {
  console.log('Roster rendered');
  return (
    <ul>
      {names.map((name) => (
        <li key={name}>{name}</li>
      ))}
    </ul>
  );
}

export default function Gradebook() {
  const [ticks, setTicks] = useState(0);
  const names = ['Asha', 'Ravi', 'Meera'].map((n) => n.toUpperCase());

  return (
    <div>
      <button onClick={() => setTicks(ticks + 1)}>Ticks: {ticks}</button>
      <Roster names={names} />
    </div>
  );
}

The component has no useMemo, useCallback or memo. Without the compiler, names is a new array on every render, so Roster rendered again after the tick button was pressed once: the console showed two lines. With babel-plugin-react-compiler 1.0.0 applied, the same code logged one line, because the compiler cached names and the Roster element. Both runs used React 19 in jsdom. Output without the compiler: Roster rendered Roster rendered

Key points

  • React Compiler adds memoization at build time using Rules of React analysis. It reached 1.0 in October 2025.
  • Correct code behaves the same. Components that break the rules are skipped, and the linter explains why.
  • Manual useMemo, useCallback and memo become an escape hatch, not a default.
  • Adopt gradually with directives and compilation modes.
  • It does not replace profiling, virtualization or good data loading.

Common mistakes

  • Believing the compiler fixes code that mutates props or state.
  • Removing all manual memoization at once without measuring.
  • Expecting speedups without profiling the actual bottleneck.
  • Disabling the compiler lint rules instead of fixing the violations.
  • Using refs in render and then wondering why a component is skipped.

Follow-ups

  • Which patterns make the compiler skip a component?
  • Would you remove existing useMemo calls after enabling the compiler? Why or why not?
  • How would you roll out the compiler in a large codebase?

Tips

  • Describe the mechanism (cache plus Object.is comparison), not just "it memoizes for you".
  • Say that correct code is a precondition. It links the compiler to the Rules of React.
  • State a rollout plan (annotation mode, directories). It shows practical thinking.