Home / Function/ ReactElement() — react Function Reference

ReactElement() — react Function Reference

Architecture documentation for the ReactElement() function in ReactJSXElement.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6["ReactElement()"]
  1bf5591f_27a1_c79f_853a_6242549e0e07["ReactJSXElement.js"]
  9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6 -->|defined in| 1bf5591f_27a1_c79f_853a_6242549e0e07
  541966e9_c9c6_423b_909d_7502d44146b3["jsxProd()"]
  541966e9_c9c6_423b_909d_7502d44146b3 -->|calls| 9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6
  ad281e06_8a7d_3988_f68c_33f816bae40c["jsxDEVImpl()"]
  ad281e06_8a7d_3988_f68c_33f816bae40c -->|calls| 9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6
  12bdbda4_5438_2837_0178_e722d4b02c99["createElement()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| 9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6
  b08010e3_571c_f8e9_f77b_875161a3dce7["cloneAndReplaceKey()"]
  b08010e3_571c_f8e9_f77b_875161a3dce7 -->|calls| 9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6
  e25f8b64_9c1b_41a7_d00a_3663a86ab332["cloneElement()"]
  e25f8b64_9c1b_41a7_d00a_3663a86ab332 -->|calls| 9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6
  style 9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react/src/jsx/ReactJSXElement.js lines 170–283

function ReactElement(type, key, props, owner, debugStack, debugTask) {
  // Ignore whatever was passed as the ref argument and treat `props.ref` as
  // the source of truth. The only thing we use this for is `element.ref`,
  // which will log a deprecation warning on access. In the next release, we
  // can remove `element.ref` as well as the `ref` argument.
  const refProp = props.ref;

  // An undefined `element.ref` is coerced to `null` for
  // backwards compatibility.
  const ref = refProp !== undefined ? refProp : null;

  let element;
  if (__DEV__) {
    // In dev, make `ref` a non-enumerable property with a warning. It's non-
    // enumerable so that test matchers and serializers don't access it and
    // trigger the warning.
    //
    // `ref` will be removed from the element completely in a future release.
    element = {
      // This tag allows us to uniquely identify this as a React Element
      $$typeof: REACT_ELEMENT_TYPE,

      // Built-in properties that belong on the element
      type,
      key,

      props,

      // Record the component responsible for creating this element.
      _owner: owner,
    };
    if (ref !== null) {
      Object.defineProperty(element, 'ref', {
        enumerable: false,
        get: elementRefGetterWithDeprecationWarning,
      });
    } else {
      // Don't warn on access if a ref is not given. This reduces false
      // positives in cases where a test serializer uses
      // getOwnPropertyDescriptors to compare objects, like Jest does, which is
      // a problem because it bypasses non-enumerability.
      //
      // So unfortunately this will trigger a false positive warning in Jest
      // when the diff is printed:
      //
      //   expect(<div ref={ref} />).toEqual(<span ref={ref} />);
      //
      // A bit sketchy, but this is what we've done for the `props.key` and
      // `props.ref` accessors for years, which implies it will be good enough
      // for `element.ref`, too. Let's see if anyone complains.
      Object.defineProperty(element, 'ref', {
        enumerable: false,
        value: null,
      });
    }
  } else {
    // In prod, `ref` is a regular property and _owner doesn't exist.
    element = {
      // This tag allows us to uniquely identify this as a React Element
      $$typeof: REACT_ELEMENT_TYPE,

      // Built-in properties that belong on the element
      type,
      key,
      ref,

      props,
    };
  }

  if (__DEV__) {
    // The validation flag is currently mutative. We put it on
    // an external backing store so that we can freeze the whole object.
    // This can be replaced with a WeakMap once they are implemented in
    // commonly used development environments.
    element._store = {};

    // To make comparing ReactElements easier for testing purposes, we make
    // the validation flag non-enumerable (where possible, which should
    // include every environment we run tests in), so the test framework
    // ignores it.

Domain

Subdomains

Frequently Asked Questions

What does ReactElement() do?
ReactElement() is a function in the react codebase, defined in packages/react/src/jsx/ReactJSXElement.js.
Where is ReactElement() defined?
ReactElement() is defined in packages/react/src/jsx/ReactJSXElement.js at line 170.
What calls ReactElement()?
ReactElement() is called by 5 function(s): cloneAndReplaceKey, cloneElement, createElement, jsxDEVImpl, jsxProd.

Analyze Your Own Codebase

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

Try Supermodel Free