Home / Function/ UnmemoizedCallbackCapturedInContextVariable() — react Function Reference

UnmemoizedCallbackCapturedInContextVariable() — react Function Reference

Architecture documentation for the UnmemoizedCallbackCapturedInContextVariable() function in error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  906b4d1c_04d6_9cd3_bfb1_de61e447b17a["UnmemoizedCallbackCapturedInContextVariable()"]
  aa2cbd6e_1456_3777_574a_0fe679c06ca5["error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx"]
  906b4d1c_04d6_9cd3_bfb1_de61e447b17a -->|defined in| aa2cbd6e_1456_3777_574a_0fe679c06ca5
  style 906b4d1c_04d6_9cd3_bfb1_de61e447b17a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx lines 5–30

function UnmemoizedCallbackCapturedInContextVariable({cond1, cond2}) {
  // The return value is captured by `x` which is a context variable, which
  // extends a's range to include the call instruction. This prevents the entire
  // range from being memoized
  const a = useHook();
  // Because b is also part of that same mutable range, it can't be memoized either
  const b = useMemo(() => ({}), []);

  // Conditional assignment without a subsequent mutation normally doesn't create a mutable
  // range, but in this case we're reassigning a context variable
  let x;
  if (cond1) {
    x = a;
  } else if (cond2) {
    x = b;
  } else {
    return null;
  }

  const f = () => {
    return x;
  };
  const result = f();

  return <ValidateMemoization inputs={[cond1, cond2]} output={result} />;
}

Subdomains

Frequently Asked Questions

What does UnmemoizedCallbackCapturedInContextVariable() do?
UnmemoizedCallbackCapturedInContextVariable() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx.
Where is UnmemoizedCallbackCapturedInContextVariable() defined?
UnmemoizedCallbackCapturedInContextVariable() is defined in compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-repro-unmemoized-callback-captured-in-context-variable.tsx at line 5.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free