Home / Function/ createElement() — react Function Reference

createElement() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  12bdbda4_5438_2837_0178_e722d4b02c99["createElement()"]
  1bf5591f_27a1_c79f_853a_6242549e0e07["ReactJSXElement.js"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|defined in| 1bf5591f_27a1_c79f_853a_6242549e0e07
  79da1863_e9f9_d1a8_fbf7_51287452d2c5["validateChildKeys()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| 79da1863_e9f9_d1a8_fbf7_51287452d2c5
  04bd1671_ef17_1a3e_4550_297a31a727d2["hasValidKey()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| 04bd1671_ef17_1a3e_4550_297a31a727d2
  1b0887cd_9134_1155_2c11_e7904b1a4478["defineKeyPropWarningGetter()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| 1b0887cd_9134_1155_2c11_e7904b1a4478
  9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6["ReactElement()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| 9e375f3a_dd2f_18ab_e2b2_0d6efc63b4b6
  5c6da8c1_f2fa_cf23_63c2_fe9e5615d850["getOwner()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| 5c6da8c1_f2fa_cf23_63c2_fe9e5615d850
  32f94b33_ccff_4b15_3949_ffacdfe3b7cf["createTask()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| 32f94b33_ccff_4b15_3949_ffacdfe3b7cf
  d690579a_a09b_f8d4_5bde_d0dee8d54086["getTaskName()"]
  12bdbda4_5438_2837_0178_e722d4b02c99 -->|calls| d690579a_a09b_f8d4_5bde_d0dee8d54086
  style 12bdbda4_5438_2837_0178_e722d4b02c99 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react/src/jsx/ReactJSXElement.js lines 610–746

export function createElement(type, config, children) {
  if (__DEV__) {
    // We don't warn for invalid element type here because with owner stacks,
    // we error in the renderer. The renderer is the only one that knows what
    // types are valid for this particular renderer so we let it error there.

    // Skip key warning if the type isn't valid since our key validation logic
    // doesn't expect a non-string/function type and can throw confusing
    // errors. We don't want exception behavior to differ between dev and
    // prod. (Rendering will throw with a helpful message and as soon as the
    // type is fixed, the key warnings will appear.)
    for (let i = 2; i < arguments.length; i++) {
      validateChildKeys(arguments[i]);
    }

    // Unlike the jsx() runtime, createElement() doesn't warn about key spread.
  }

  let propName;

  // Reserved names are extracted
  const props = {};

  let key = null;

  if (config != null) {
    if (__DEV__) {
      if (
        !didWarnAboutOldJSXRuntime &&
        '__self' in config &&
        // Do not assume this is the result of an oudated JSX transform if key
        // is present, because the modern JSX transform sometimes outputs
        // createElement to preserve precedence between a static key and a
        // spread key. To avoid false positive warnings, we never warn if
        // there's a key.
        !('key' in config)
      ) {
        didWarnAboutOldJSXRuntime = true;
        console.warn(
          'Your app (or one of its dependencies) is using an outdated JSX ' +
            'transform. Update to the modern JSX transform for ' +
            'faster performance: https://react.dev/link/new-jsx-transform',
        );
      }
    }

    if (hasValidKey(config)) {
      if (enableOptimisticKey && config.key === REACT_OPTIMISTIC_KEY) {
        key = REACT_OPTIMISTIC_KEY;
      } else {
        if (__DEV__) {
          checkKeyStringCoercion(config.key);
        }
        key = '' + config.key;
      }
    }

    // Remaining properties are added to a new props object
    for (propName in config) {
      if (
        hasOwnProperty.call(config, propName) &&
        // Skip over reserved prop names
        propName !== 'key' &&
        // Even though we don't use these anymore in the runtime, we don't want
        // them to appear as props, so in createElement we filter them out.
        // We don't have to do this in the jsx() runtime because the jsx()
        // transform never passed these as props; it used separate arguments.
        propName !== '__self' &&
        propName !== '__source'
      ) {
        props[propName] = config[propName];
      }
    }
  }

  // Children can be more than one argument, and those are transferred onto
  // the newly allocated props object.
  const childrenLength = arguments.length - 2;
  if (childrenLength === 1) {
    props.children = children;
  } else if (childrenLength > 1) {

Domain

Subdomains

Frequently Asked Questions

What does createElement() do?
createElement() is a function in the react codebase, defined in packages/react/src/jsx/ReactJSXElement.js.
Where is createElement() defined?
createElement() is defined in packages/react/src/jsx/ReactJSXElement.js at line 610.
What does createElement() call?
createElement() calls 7 function(s): ReactElement, createTask, defineKeyPropWarningGetter, getOwner, getTaskName, hasValidKey, validateChildKeys.

Analyze Your Own Codebase

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

Try Supermodel Free