"use no memo" prevents a function from being optimized by React Compiler.
"use no memo"
Add "use no memo" at the beginning of a function to prevent React Compiler optimization.
function MyComponent() {
"use no memo";
// ...
} When a function contains "use no memo", the React Compiler will skip it entirely during optimization. This is useful as a temporary escape hatch when debugging or when dealing with code that doesn’t work correctly with the compiler.
"use no memo" must be at the very beginning of a function body, before any imports or other code (comments are OK)."use no memo" or its alias "use no forget"."use no memo" opts-out of optimization
React Compiler analyzes your code at build time to apply optimizations. "use no memo" creates an explicit boundary that tells the compiler to skip a function entirely.
This directive takes precedence over all other settings:
all mode: The function is skipped despite the global settinginfer mode: The function is skipped even if heuristics would optimize itThe compiler treats these functions as if the React Compiler wasn’t enabled, leaving them exactly as written.
"use no memo"
"use no memo" should be used sparingly and temporarily. Common scenarios include:
When you suspect the compiler is causing issues, temporarily disable optimization to isolate the problem:
function ProblematicComponent({ data }) {
"use no memo"; // TODO: Remove after fixing issue #123
// Rules of React violations that weren't statically detected
// ...
} When integrating with libraries that might not be compatible with the compiler:
function ThirdPartyWrapper() {
"use no memo";
useThirdPartyHook(); // Has side effects that compiler might optimize incorrectly
// ...
} The "use no memo" directive is placed at the beginning of a function body to prevent React Compiler from optimizing that function:
function MyComponent() {
"use no memo";
// Function body
} The directive can also be placed at the top of a file to affect all functions in that module:
"use no memo";
// All functions in this file will be skipped by the compiler "use no memo" at the function level overrides the module level directive.
If "use no memo" isn’t working:
// ❌ Wrong - directive after code
function Component() {
const data = getData();
"use no memo"; // Too late!
}
// ✅ Correct - directive first
function Component() {
"use no memo";
const data = getData();
} Also check:
"use no memo"
Always document why you’re disabling optimization:
// ✅ Good - clear explanation and tracking
function DataProcessor() {
"use no memo"; // TODO: Remove after fixing rule of react violation
// ...
}
// ❌ Bad - no explanation
function Mystery() {
"use no memo";
// ...
} "use memo" - Opt into compilation
© 2013–present Facebook Inc.
Licensed under the Creative Commons Attribution 4.0 International Public License.
https://react.dev/reference/react-compiler/directives/use-no-memo