For years, keeping a React app fast meant sprinkling useMemo, useCallback and React.memo through your components, then arguing in code review about whether each one was worth it. React Compiler changes that. It is a build-time tool that reads your components and hooks and adds the memoisation for you.

React Compiler 1.0 shipped as a stable release in October 2025, so it is no longer an experiment. This article is for developers who already know React and want a clear picture of what the compiler does, how to switch it on, what it relies on, and the handful of places where a manual useMemo still makes sense.

What React Compiler actually does

#

React re-renders a component whenever its state, props or context change, and by default it re-renders that component's children too. Most of the time this is cheap. When it is not, the classic fix is manual memoisation: cache a value with useMemo, keep a function stable with useCallback, and wrap a child in React.memo so it skips renders when its props have not changed.

The compiler does the equivalent work automatically. It runs as a Babel plugin during your build, analyses each component and hook, and rewrites them so that values, functions and JSX are only recalculated when the things they depend on change.

Take this component:


_15
function ProductList({ products, onSelect }) {
_15
const sorted = products.toSorted((a, b) => a.price - b.price);
_15
_15
const handleClick = (product) => {
_15
onSelect(product.id);
_15
};
_15
_15
return (
_15
<ul>
_15
{sorted.map((product) => (
_15
<ProductRow key={product.id} product={product} onClick={handleClick} />
_15
))}
_15
</ul>
_15
);
_15
}

Without the compiler, every render sorts the array again, creates a new handleClick, and re-renders every ProductRow. With the compiler, the sorted array, the handler and the rendered rows are all cached and only rebuilt when products or onSelect change. You write the plain version and get the optimised one.

If you look at the compiled output you will see an import from react/compiler-runtime and a small cache array that the component reads from and writes to. You never write this code yourself, but knowing it is there helps when you want to confirm the compiler has run.

Setting it up

#

Install the Babel plugin as a dev dependency. This is needed in every setup, including Next.js.


_10
npm install -D babel-plugin-react-compiler@latest

Next.js

Next.js has a built-in option. In Next.js 16 it is a stable, top-level setting (in Next.js 15 it lived under experimental).


_10
// next.config.ts
_10
import type { NextConfig } from 'next';
_10
_10
const nextConfig: NextConfig = {
_10
reactCompiler: true,
_10
};
_10
_10
export default nextConfig;

Next.js uses an SWC step to decide which files actually need the compiler (files with JSX or hooks), so the build cost stays small. Do not also add the Babel plugin to a custom Babel config, or your code will be compiled twice.

Vite

The setup depends on your version of @vitejs/plugin-react. From version 6, the inline Babel option was removed and the compiler runs through @rolldown/plugin-babel with a preset:


_10
npm install -D @rolldown/plugin-babel


_13
// vite.config.js
_13
import { defineConfig } from 'vite';
_13
import react, { reactCompilerPreset } from '@vitejs/plugin-react';
_13
import babel from '@rolldown/plugin-babel';
_13
_13
export default defineConfig({
_13
plugins: [
_13
react(),
_13
babel({
_13
presets: [reactCompilerPreset()],
_13
}),
_13
],
_13
});

On older versions of @vitejs/plugin-react you pass the plugin through its babel option instead:


_13
// vite.config.js
_13
import { defineConfig } from 'vite';
_13
import react from '@vitejs/plugin-react';
_13
_13
export default defineConfig({
_13
plugins: [
_13
react({
_13
babel: {
_13
plugins: ['babel-plugin-react-compiler'],
_13
},
_13
}),
_13
],
_13
});

Plain Babel

For any other Babel-based build, add the plugin and make sure it runs first, because it needs the original source to analyse.


_10
// babel.config.js
_10
module.exports = {
_10
plugins: [
_10
'babel-plugin-react-compiler', // must run first
_10
// other plugins
_10
],
_10
};

If you are starting a new project, the create-next-app and create-vite templates both offer a compiler-enabled option.

What it memoises

#

It helps to be precise about the scope, because this is where most confusion comes from.

  • JSX and child components. The compiler caches the JSX a component returns, so a child only re-renders when the props it receives actually change. This covers most of what React.memo used to do for you.
  • Derived values. Calculations during render, like the sorted array above, are cached against their inputs.
  • Functions. Event handlers and callbacks defined inside a component keep a stable identity between renders, so you rarely need useCallback. Inline arrow functions in JSX no longer break memoisation either.
  • Fine-grained updates. The compiler can memoise parts of a component separately, so a change to one piece of state does not force everything else in that component to be rebuilt.

There are also clear limits:

  • It only compiles components and hooks. A plain utility function outside a component is left alone.
  • Memoisation is not shared between components. If two components run the same expensive calculation, each keeps its own cached copy.
  • It caches based on inputs it can see. It does not know that a value from an external store or a mutable object has changed unless that change comes through props, state or context.

The Rules of React it relies on

#

The compiler can only add caching safely if your code follows the Rules of React. If a component secretly depends on something changing during render, caching its output would show stale UI. The main rules are:

  • Components and hooks must be pure: the same props, state and context give the same output, with no side effects during render.
  • Props and state are immutable. You create new values instead of changing existing ones.
  • Values passed to JSX or hooks are not mutated afterwards.
  • Hooks are called at the top level, never inside conditions or loops.
  • Refs are not read or written during render, only in effects and event handlers.

Here is a pattern that breaks the rules:


_10
function Cart({ items }) {
_10
let total = 0;
_10
items.forEach((item) => {
_10
item.lineTotal = item.price * item.quantity; // mutates a prop
_10
total += item.lineTotal;
_10
});
_10
_10
return <Summary items={items} total={total} />;
_10
}

Mutating item changes an object that came in through props. The safer version builds new values:


_10
function Cart({ items }) {
_10
const lines = items.map((item) => ({
_10
...item,
_10
lineTotal: item.price * item.quantity,
_10
}));
_10
const total = lines.reduce((sum, line) => sum + line.lineTotal, 0);
_10
_10
return <Summary items={lines} total={total} />;
_10
}

The good news is that the compiler is cautious. When it detects code it cannot prove is safe, it skips that component or hook and leaves it as it was, rather than producing broken output. Your app keeps working; that component simply does not get the automatic optimisation.

The ESLint plugin

#

The compiler's checks are surfaced through eslint-plugin-react-hooks, the same package that gives you the long-standing rules-of-hooks and exhaustive-deps rules. Install the latest version:


_10
npm install -D eslint-plugin-react-hooks@latest

Then use the recommended preset in a flat config:


_10
// eslint.config.js
_10
import reactHooks from 'eslint-plugin-react-hooks';
_10
import { defineConfig } from 'eslint/config';
_10
_10
export default defineConfig([
_10
reactHooks.configs.flat.recommended,
_10
]);

There is also a recommended-latest preset if you want the newest compiler rules as they land. The compiler-related rules include react-hooks/purity, react-hooks/immutability, react-hooks/refs, react-hooks/set-state-in-render, react-hooks/set-state-in-effect, react-hooks/static-components, react-hooks/preserve-manual-memoization and react-hooks/incompatible-library.

Each error points to a component the compiler will skip. You do not need to fix every warning before turning the compiler on. Treat the lint output as a to-do list: the more you fix, the more of your app gets optimised.

Opting out with "use no memo"

#

Sometimes a component misbehaves after compilation, usually because it breaks a rule in a way the compiler did not catch. While you investigate, you can exclude it with a directive at the top of the function body:


_10
function LegacyChart({ data }) {
_10
'use no memo';
_10
_10
// this component is left uncompiled
_10
const chart = useLegacyChartLibrary(data);
_10
return <div ref={chart.containerRef} />;
_10
}

Think of "use no memo" as a temporary escape hatch, not a permanent setting. Leave a comment explaining why it is there and come back to fix the underlying problem.

The opposite approach is useful for a gradual rollout. In annotation mode the compiler only touches components that opt in with "use memo":


_10
// next.config.ts
_10
const nextConfig = {
_10
reactCompiler: {
_10
compilationMode: 'annotation',
_10
},
_10
};
_10
_10
export default nextConfig;


_10
function Dashboard() {
_10
'use memo';
_10
// only components with this directive are compiled
_10
}

This lets you enable the compiler on one screen at a time on a large codebase.

How to check it is working

#

There are three quick ways to confirm the compiler is running.

  1. React DevTools. Open your app in development mode and look at the Components tab. Components the compiler optimised show a "Memo" badge with a sparkle next to their name. If a component you expected to see is missing the badge, the compiler probably skipped it, and the ESLint plugin should tell you why.
  2. The build output. Search your built JavaScript for react/compiler-runtime. If it appears, compiled components are in the bundle.
  3. The Profiler. Record an interaction in the DevTools Profiler before and after enabling the compiler. You should see fewer components re-rendering when a single piece of state changes.

When you still need useMemo

#

The React team's guidance is to rely on the compiler for new code and reach for useMemo and useCallback only when you need precise control. In practice that leaves a few cases.

Effect dependencies that must stay stable

This is the main one. If a value is used as an effect dependency, you may want a firm guarantee that the effect does not fire again unless something meaningful changed. The compiler's memoisation is an optimisation it is free to apply as it sees fit, while useMemo states your intent explicitly.


_13
function LiveFeed({ roomId, filters }) {
_13
const options = useMemo(
_13
() => ({ roomId, topics: filters.topics }),
_13
[roomId, filters.topics]
_13
);
_13
_13
useEffect(() => {
_13
const connection = connect(options);
_13
return () => connection.close();
_13
}, [options]);
_13
_13
// ...
_13
}

Existing memoisation in a working codebase

If your code already uses useMemo and useCallback, the advice is to leave them in place, or to test carefully before removing them. Removing manual memoisation can change what the compiler produces. The preserve-manual-memoization lint rule helps spot cases where the compiler cannot keep the guarantees your existing hooks give.

Components the compiler skips

Any component the compiler bails out of gets no automatic memoisation. If it is on a hot path and you cannot refactor it yet, manual memoisation is still a valid fix.

Libraries that do not follow the rules

Some third-party libraries return values that change through mutation rather than new references. The compiler cannot see those changes, and the incompatible-library rule flags known cases. Those components may need "use no memo" or careful manual handling.

Work shared across components

Because memoisation is per component, an expensive calculation used in several places runs once in each. Lift it into a shared parent, compute it on the server, or cache it outside React.

Version support

#
  • React 19 works with the compiler directly.
  • React 17 and 18 are supported too. You install the react-compiler-runtime package and set the compiler's target option to your React version. Check the React Compiler docs for the exact configuration for your version.
  • Next.js: the reactCompiler option became stable and top-level in Next.js 16. The React team recommends Next.js 15.3.1 or later if you are on 15.
  • Vite: @vitejs/plugin-react 6 and later use the reactCompilerPreset with @rolldown/plugin-babel; earlier versions use the inline babel option.

When not to use it

#

The compiler is a good default for most React apps, but there are times to hold off or roll out slowly.

  • A large codebase with many rule violations and few tests. The compiler skips what it detects, but a subtle violation it misses could show stale UI. Run the ESLint rules first, fix the noisy areas, and use annotation mode to start small.
  • Code built around mutation. If a feature depends on mutating objects during render or on libraries that work that way, it will either be skipped or need opting out. The benefit there is small.
  • Builds where every second counts. The compiler adds a Babel pass. Next.js limits this to relevant files, but on very large projects it is still worth measuring build times before and after.
  • When performance is already fine. If your app has no rendering problems, the compiler is still low risk, but there is no urgency. Adopt it when you next upgrade tooling rather than as an emergency fix.

Wrapping up

#
  • React Compiler 1.0 is stable and memoises components, values, functions and JSX at build time, so you write plain React and get the optimised version.
  • It relies on the Rules of React. Where it cannot prove code is safe, it skips that component rather than breaking it.
  • Use the eslint-plugin-react-hooks recommended preset to find the components it skips, and "use no memo" as a temporary opt-out.
  • Check it is working with the "Memo" badge in React DevTools or by searching your build for react/compiler-runtime.
  • Keep useMemo for effect dependencies that must stay stable, for existing code you have not tested without it, and for components the compiler cannot optimise.
#
file under:
React

Was this article helpful?

About the author

Danny Engineering

A software engineer with a strong belief in human-centric design and driven by a deep empathy for users. Combining the latest technology with human values to build a better, more connected world.