You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2551636
Browse filesBrowse the repository at this point in the historyBrowse files
React Compiler directives provide fine-grained control over which functions are optimized by the compiler. They are string literals placed at the beginning of a function body or at the top of a module.
In most cases, you don't need `"use memo"`. It's primarily needed in `annotation`mode where you must explicitly mark functions for optimization. In `infer`mode, the compiler automatically detects components and hooks by their naming patterns (PascalCase for components, `use`prefix for hooks). If a component or hook isn't being compiled in `infer`mode, you should fix its naming convention rather than forcing compilation with `"use memo"`.
When a function contains `"use memo"`, the React Compiler will analyze and optimize it during build time. The compiler will automatically memoize values and components to prevent unnecessary re-computations and re-renders.
In a React app that uses the React Compiler, functions are analyzed at build time to determine if they can be optimized. By default, the compiler automatically infers which components to memoize, but this can depend on your [`compilationMode`](/reference/react-compiler/compilationMode)setting if you've set it.
The directive creates a clear boundary in your codebase between optimized and non-optimized code, giving you fine-grained control over the compilation process.
// Automatically memoized because this is named like a Component
130
130
functionComplexDashboard({ data }) {
@@ -137,21 +137,21 @@ function simpleDisplay({ text }) {
137
137
}
138
138
```
139
139
140
-
In `infer`mode, the compiler automatically detects components and hooks by their naming patterns (PascalCase for components, `use`prefix for hooks). If a component or hook isn't being compiled in `infer`mode, you should fix its naming convention rather than forcing compilation with `"use memo"`.
0 commit comments