useReactCompiler
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useReactCompiler - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useReactCompiler": "error" } } }}Description
Section titled “Description”Validate files with React Compiler.
This rule runs React Compiler in lint mode and reports the actionable diagnostics it emits. React Compiler validates whether components and hooks can be safely compiled.
This rule only runs when the nearest package.json declares React 19 or
newer. Projects using React 18 or earlier, or projects without a React
dependency in package.json, are skipped.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”{ "dependencies": { "react": "^19.0.0" }}import { useState } from "react";
function Component(props) { if (props.enabled) { useState(0); }
return <div />;}/Component.jsx:5:9 lint/nursery/useReactCompiler ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This hook usage does not follow React’s rules.
3 │ function Component(props) {
4 │ if (props.enabled) {
> 5 │ useState(0);
│ ^^^^^^^^
6 │ }
7 │
ℹ Hooks must be called directly at the top level of a component or custom hook, and in the same order on every render.
ℹ Move the hook call to the top level, and call a statically known hook directly instead of passing, storing, or selecting it dynamically.
ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/10974 for more information or to report possible bugs.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
function Component(props) { return <div>{props.value}</div>;}Options
Section titled “Options”compilationMode
Section titled “compilationMode”Controls which functions React Compiler analyzes. Accepted values are:
"infer"(default): analyzes functions that follow React conventions — components (capitalized functions that create JSX or call hooks) and hooks (functions whose name starts withuse). Files that don’t define any such function are skipped entirely."annotation": analyzes only functions annotated with a"use memo"directive."all": analyzes every function. This can report React-specific diagnostics in non-React code, such as utility functions that update module-level state.
{ "linter": { "rules": { "nursery": { "useReactCompiler": { "level": "on", "options": { "compilationMode": "all" } } } } }}With "compilationMode": "all", violations are reported even in
functions that don’t follow React naming conventions:
{ "dependencies": { "react": "^19.0.0" }}let counter = 0;
export function increment() { counter = counter + 1; return counter;}/counter.js:4:5 lint/nursery/useReactCompiler ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This component reassigns a variable declared outside it.
3 │ export function increment() {
> 4 │ counter = counter + 1;
│ ^^^^^^^
5 │ return counter;
6 │ }
ℹ Changing external variables during render makes component output depend on mutable shared state.
ℹ Keep render logic local and immutable, or move shared updates into state, refs, or event handlers.
ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/10974 for more information or to report possible bugs.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.