Home / Function/ Component() — react Function Reference

Component() — react Function Reference

Architecture documentation for the Component() function in error.invalid-reassign-local-variable-in-hook-argument.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  3fe23b6f_04db_e9a7_4fdf_2ab26c420441["Component()"]
  375daf16_10c5_05a6_0aa6_35720a8f6f50["error.invalid-reassign-local-variable-in-hook-argument.js"]
  3fe23b6f_04db_e9a7_4fdf_2ab26c420441 -->|defined in| 375daf16_10c5_05a6_0aa6_35720a8f6f50
  style 3fe23b6f_04db_e9a7_4fdf_2ab26c420441 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-hook-argument.js lines 4–39

function Component() {
  let local;

  const reassignLocal = newValue => {
    local = newValue;
  };

  const callback = newValue => {
    reassignLocal('hello');

    if (local === newValue) {
      // Without React Compiler, `reassignLocal` is freshly created
      // on each render, capturing a binding to the latest `local`,
      // such that invoking reassignLocal will reassign the same
      // binding that we are observing in the if condition, and
      // we reach this branch
      console.log('`local` was updated!');
    } else {
      // With React Compiler enabled, `reassignLocal` is only created
      // once, capturing a binding to `local` in that render pass.
      // Therefore, calling `reassignLocal` will reassign the wrong
      // version of `local`, and not update the binding we are checking
      // in the if condition.
      //
      // To protect against this, we disallow reassigning locals from
      // functions that escape
      throw new Error('`local` not updated!');
    }
  };

  useIdentity(() => {
    callback();
  });

  return 'ok';
}

Subdomains

Frequently Asked Questions

What does Component() do?
Component() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-hook-argument.js.
Where is Component() defined?
Component() is defined in compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-hook-argument.js at line 4.

Analyze Your Own Codebase

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

Try Supermodel Free