# React Compiler

> The React Compiler is a build-time tool that automatically optimizes React components with memoization.

## What does the React Compiler do and do I still need useMemo?

The build-time tool that analyzes components and hooks and automatically applies memoization. Reduces the need for manual `useMemo()`, `useCallback()` and `memo()`, but requires following the Rules of React.

- Topic: Basics
- Type: concept, tool

## Example

Wrong:

```jsx
const visible = useMemo(
  () => todos.filter((t) => !t.done),
  [todos]
);
const onToggle = useCallback((id) => toggle(id), [toggle]);
```

Right:

```jsx
const visible = todos.filter((t) => !t.done);
const onToggle = (id) => toggle(id);
```

With the compiler on, plain code is memoized automatically, so new code skips manual `useMemo` and `useCallback`.

## Common mistakes

- A component stops updating because it mutates an object instead of creating a new one.
- Deleting all existing manual memoization at once, changing effect timing in subtle ways.

## Key points

- New code does not add `useMemo`, `useCallback` or `memo()` by default when the compiler is enabled.
- Components and hooks are pure: no mutation of props, state or values read during render.
- The React Hooks lint rules are enabled to catch code the compiler has to skip.

## Interview questions

### Do I need to rewrite my code for the React Compiler?

No, it works on existing code that follows the Rules of React. Components it cannot safely optimize are skipped and keep working as before.

### Can I opt a component out of the React Compiler?

Yes, add the 'use no memo' directive at the top of the component or file to skip it temporarily.

### Does the React Compiler run in the browser?

No, it runs at build time as a compiler plugin and outputs JavaScript that uses React's normal APIs.

## Related cards

- [useMemo()](https://wonderium.dev/react/use-memo.md)
- [useCallback()](https://wonderium.dev/react/use-callback.md)
- [memo()](https://wonderium.dev/react/memo.md)
- [Rendering](https://wonderium.dev/react/rendering.md)
- [`<StrictMode>`](https://wonderium.dev/react/strict-mode.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/react-compiler
- Last updated: 2026-11-25
