Home / Function/ Component() — react Function Reference

Component() — react Function Reference

Architecture documentation for the Component() function in destructuring-mixed-scope-and-local-variables-with-default.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  b4cd7bad_7282_7a21_2c9b_ca6789b7e606["Component()"]
  4a225197_281a_417a_1d6c_72712670e704["destructuring-mixed-scope-and-local-variables-with-default.js"]
  b4cd7bad_7282_7a21_2c9b_ca6789b7e606 -->|defined in| 4a225197_281a_417a_1d6c_72712670e704
  109e89a7_ca23_36c1_2f1d_3453059ca456["useFragment()"]
  b4cd7bad_7282_7a21_2c9b_ca6789b7e606 -->|calls| 109e89a7_ca23_36c1_2f1d_3453059ca456
  style b4cd7bad_7282_7a21_2c9b_ca6789b7e606 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.js lines 11–37

function Component(props) {
  const post = useFragment(
    graphql`
      fragment F on T {
        id
      }
    `,
    props.post
  );
  const allUrls = [];
  // `media` and `urls` are exported from the scope that will wrap this code,
  // but `comments` is not (it doesn't need to be memoized, bc the callback
  // only checks `comments.length`)
  // because of the scope, the let declaration for media and urls are lifted
  // out of the scope, and the destructure statement ends up turning into
  // a reassignment, instead of a const declaration. this means we try to
  // reassign `comments` when there's no declaration for it.
  const {media = null, comments = [], urls = []} = post;
  const onClick = e => {
    if (!comments.length) {
      return;
    }
    console.log(comments.length);
  };
  allUrls.push(...urls);
  return <Stringify media={media} allUrls={allUrls} onClick={onClick} />;
}

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/destructuring-mixed-scope-and-local-variables-with-default.js.
Where is Component() defined?
Component() is defined in compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.js at line 11.
What does Component() call?
Component() calls 1 function(s): useFragment.

Analyze Your Own Codebase

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

Try Supermodel Free