React Compiler
February 9, 20261 min readpart 10/13
The React Compiler (originally "React Forget") is an AOT compiler that automatically memoizes components and hooks at build time. It tracks which variables depend on which reactive inputs and groups them into reactive scopes:
// What you write:
function TodoList({ todos, filter }) {
const filtered = todos.filter(t => t.status === filter);
return <List items={filtered} />;
}
// What the compiler outputs (conceptually):
function TodoList({ todos, filter }) {
const $ = useMemoCache(4);
if ($[0] !== todos || $[1] !== filter) {
$[2] = todos.filter(t => t.status === filter);
$[0] = todos;
$[1] = filter;
}
return $[2];
}Further reading
- React Compiler — Official Docs (docs) Setup guide, rules, and how the compiler understands your code
- React Compiler Talk — React Conf 2024 (video) Core team on reactive scopes, analysis passes, and useMemoCache
- React Compiler Playground (tool) Paste any component and see the compiled output in real time
- React Compiler In Depth (article) Nadia Makarevich on what the compiler can and cannot optimize
- React Compiler Source (source) The compiler implementation in the React monorepo