logo by @sawaratsuki1004
React
v19.2
تعلم
مرجع
المجتمع
المدونة

هل هذه الصفحة مفيدة؟

في هذه الصفحة

  • Overview
  • Reference
  • "use no memo"
  • How "use no memo" opts-out of optimization
  • When to use "use no memo"
  • Usage
  • Troubleshooting
  • Directive not preventing compilation
  • Best practices
  • See also

    react@19.2

  • نظرة عامة
  • Hooks
    • useActionState
    • useCallback
    • useContext
    • useDebugValue
    • useDeferredValue
    • useEffect
    • useEffectEvent
    • useId
    • useImperativeHandle
    • useInsertionEffect
    • useLayoutEffect
    • useMemo
    • useOptimistic
    • useReducer
    • useRef
    • useState
    • useSyncExternalStore
    • useTransition
  • المكونات
    • <Fragment> (<>)
    • <Profiler>
    • <StrictMode>
    • <Suspense>
    • <Activity>
    • <ViewTransition> - هذه الميزة متاحة في أحدث إصدار Canary من React
  • APIs
    • act
    • addTransitionType - هذه الميزة متاحة في أحدث إصدار Canary من React
    • cache
    • cacheSignal
    • captureOwnerStack
    • createContext
    • lazy
    • memo
    • startTransition
    • use
    • experimental_taintObjectReference - هذه الميزة متاحة في أحدث إصدار تجريبي من React
    • experimental_taintUniqueValue - هذه الميزة متاحة في أحدث إصدار تجريبي من React
  • react-dom@19.2

  • Hooks
    • useFormStatus
  • المكونات (Components)
    • Common (e.g. <div>)
    • <form>
    • <input>
    • <option>
    • <progress>
    • <select>
    • <textarea>
    • <link>
    • <meta>
    • <script>
    • <style>
    • <title>
  • APIs
    • createPortal
    • flushSync
    • preconnect
    • prefetchDNS
    • preinit
    • preinitModule
    • preload
    • preloadModule
  • Client APIs
    • createRoot
    • hydrateRoot
  • Server APIs
    • renderToPipeableStream
    • renderToReadableStream
    • renderToStaticMarkup
    • renderToString
    • resume
    • resumeToPipeableStream
  • Static APIs
    • prerender
    • prerenderToNodeStream
    • resumeAndPrerender
    • resumeAndPrerenderToNodeStream
  • React Compiler

  • الإعدادات (Configuration)
    • compilationMode
    • gating
    • logger
    • panicThreshold
    • target
  • Directives
    • "use memo"
    • "use no memo"
  • تصريف المكتبات (Compiling Libraries)
  • React DevTools

  • React Performance tracks
  • eslint-plugin-react-hooks

  • Lints
    • exhaustive-deps
    • rules-of-hooks
    • component-hook-factories
    • config
    • error-boundaries
    • gating
    • globals
    • immutability
    • incompatible-library
    • preserve-manual-memoization
    • purity
    • refs
    • set-state-in-effect
    • set-state-in-render
    • static-components
    • unsupported-syntax
    • use-memo
  • قواعد React (Rules of React)

  • نظرة عامة (Overview)
    • Components و Hooks يجب أن تكون Pure
    • React تستدعي Components و Hooks
    • قواعد Hooks
  • React Server Components

  • Server Components
  • Server Functions
  • Directives
    • 'use client'
    • 'use server'
  • Legacy APIs

  • Legacy React APIs
    • Children
    • cloneElement
    • Component
    • createElement
    • createRef
    • forwardRef
    • isValidElement
    • PureComponent
مرجع API
Directives

use no memo

"use no memo" prevents a function from being optimized by React Compiler.

  • Reference
    • "use no memo"
    • How "use no memo" opts-out of optimization
    • When to use "use no memo"
  • Usage
  • Troubleshooting
    • Directive not preventing compilation
    • Best practices
    • See also

Reference

"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.

Caveats

  • "use no memo" must be at the very beginning of a function body, before any imports or other code (comments are OK).
  • The directive must be written with double or single quotes, not backticks.
  • The directive must exactly match "use no memo" or its alias "use no forget".
  • This directive takes precedence over all compilation modes and other directives.
  • It’s intended as a temporary debugging tool, not a permanent solution.

How "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:

  • In all mode: The function is skipped despite the global setting
  • In infer mode: The function is skipped even if heuristics would optimize it

The compiler treats these functions as if the React Compiler wasn’t enabled, leaving them exactly as written.

When to use "use no memo"

"use no memo" should be used sparingly and temporarily. Common scenarios include:

Debugging compiler issues

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 // ... }

Third-party library integration

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 // ... }


Usage

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.


Troubleshooting

Directive not preventing compilation

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:

  • Spelling - must be exactly "use no memo"
  • Quotes - must use single or double quotes, not backticks

Best practices

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"; // ... }

See also

  • "use memo" - Opt into compilation
  • React Compiler - Getting started guide
السابق"use memo"
التاليتصريف المكتبات (Compiling Libraries)

Copyright © Meta Platforms, Inc
no uwu plz
uwu?
Logo by@sawaratsuki1004
تعلم React
بداية سريعة
التثبيت
وصف واجهة المستخدم (UI)
إضافة التفاعلية
إدارة State
مخارج الطوارئ
مرجع API
React APIs
React DOM APIs
المجتمع
ميثاق السلوك
تعرف على الفريق
المساهمون في التوثيق
شكر وتقدير
المزيد
المدونة
React Native
الخصوصية
الشروط
function MyComponent() {
"use no memo";
// ...
}
function ProblematicComponent({ data }) {
"use no memo"; // TODO: Remove after fixing issue #123

// Rules of React violations that weren't statically detected
// ...
}
function ThirdPartyWrapper() {
"use no memo";

useThirdPartyHook(); // Has side effects that compiler might optimize incorrectly
// ...
}
function MyComponent() {
"use no memo";
// Function body
}
"use no memo";

// All functions in this file will be skipped by the compiler
// ❌ 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();
}
// ✅ 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";
// ...
}