Home / File/ error.invalid-reassign-local-variable-in-jsx-callback.js — react Source File

error.invalid-reassign-local-variable-in-jsx-callback.js — react Source File

Architecture documentation for error.invalid-reassign-local-variable-in-jsx-callback.js, a javascript file in the react codebase.

Entity Profile

Relationship Graph

Source Code

function Component() {
  let local;

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

  const onClick = 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!');
    }
  };

  return <button onClick={onClick}>Submit</button>;
}

Subdomains

Functions

Frequently Asked Questions

What does error.invalid-reassign-local-variable-in-jsx-callback.js do?
error.invalid-reassign-local-variable-in-jsx-callback.js is a source file in the react codebase, written in javascript. It belongs to the TestingUtilities domain, Fixtures subdomain.
What functions are defined in error.invalid-reassign-local-variable-in-jsx-callback.js?
error.invalid-reassign-local-variable-in-jsx-callback.js defines 1 function(s): Component.
Where is error.invalid-reassign-local-variable-in-jsx-callback.js in the architecture?
error.invalid-reassign-local-variable-in-jsx-callback.js is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.invalid-reassign-local-variable-in-jsx-callback.js (domain: TestingUtilities, subdomain: Fixtures, directory: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler).

Analyze Your Own Codebase

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

Try Supermodel Free