---
title: "React Compiler: what it memoises and when you still need useMemo"
description: "A practical guide to React Compiler 1.0: how to set it up in Next.js, Vite and Babel, what it memoises for you, and the cases where useMemo still earns its place."
url: https://www.danny.engineering/article/react-compiler-what-it-memoises-and-when-you-still-need-usememo
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:25:00.000Z
tags: ["React", "Performance"]
---

# React Compiler: what it memoises and when you still need useMemo

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:


```typescript
function ProductList({ products, onSelect }) {
  const sorted = products.toSorted((a, b) => a.price - b.price);

  const handleClick = (product) => {
    onSelect(product.id);
  };

  return (
    <ul>
      {sorted.map((product) => (
        <ProductRow key={product.id} product={product} onClick={handleClick} />
      ))}
    </ul>
  );
}
```


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.


```bash
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`).


```typescript
// next.config.ts
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  reactCompiler: true,
};

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:


```bash
npm install -D @rolldown/plugin-babel
```


```javascript
// vite.config.js
import { defineConfig } from 'vite';
import react, { reactCompilerPreset } from '@vitejs/plugin-react';
import babel from '@rolldown/plugin-babel';

export default defineConfig({
  plugins: [
    react(),
    babel({
      presets: [reactCompilerPreset()],
    }),
  ],
});
```


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


```javascript
// vite.config.js
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [
    react({
      babel: {
        plugins: ['babel-plugin-react-compiler'],
      },
    }),
  ],
});
```


### 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.


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


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:


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

  return <Summary items={items} total={total} />;
}
```


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


```typescript
function Cart({ items }) {
  const lines = items.map((item) => ({
    ...item,
    lineTotal: item.price * item.quantity,
  }));
  const total = lines.reduce((sum, line) => sum + line.lineTotal, 0);

  return <Summary items={lines} total={total} />;
}
```


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:


```bash
npm install -D eslint-plugin-react-hooks@latest
```


Then use the recommended preset in a flat config:


```javascript
// eslint.config.js
import reactHooks from 'eslint-plugin-react-hooks';
import { defineConfig } from 'eslint/config';

export default defineConfig([
  reactHooks.configs.flat.recommended,
]);
```


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:


```typescript
function LegacyChart({ data }) {
  'use no memo';

  // this component is left uncompiled
  const chart = useLegacyChartLibrary(data);
  return <div ref={chart.containerRef} />;
}
```


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"`:


```typescript
// next.config.ts
const nextConfig = {
  reactCompiler: {
    compilationMode: 'annotation',
  },
};

export default nextConfig;
```


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


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.


```typescript
function LiveFeed({ roomId, filters }) {
  const options = useMemo(
    () => ({ roomId, topics: filters.topics }),
    [roomId, filters.topics]
  );

  useEffect(() => {
    const connection = connect(options);
    return () => connection.close();
  }, [options]);

  // ...
}
```


### 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.

## Related reading

- [React Compiler introduction](https://react.dev/learn/react-compiler/introduction)
- [React Compiler installation](https://react.dev/learn/react-compiler/installation)
- [Next.js reactCompiler option](https://nextjs.org/docs/app/api-reference/config/next-config-js/reactCompiler)
