Home / Function/ setInitialProperties() — react Function Reference

setInitialProperties() — react Function Reference

Architecture documentation for the setInitialProperties() function in ReactDOMComponent.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  96cf114b_9b89_b174_432c_1584a973fcdd["setInitialProperties()"]
  1e990658_7cea_75be_1f24_2399bdf9f15b["ReactDOMComponent.js"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|defined in| 1e990658_7cea_75be_1f24_2399bdf9f15b
  d1920c22_65b3_03a6_5c07_e0adab00dcde["validatePropertiesInDevelopment()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| d1920c22_65b3_03a6_5c07_e0adab00dcde
  9a006a44_c580_470b_507b_17fea64729bd["listenToNonDelegatedEvent()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 9a006a44_c580_470b_507b_17fea64729bd
  5a792874_dbaf_1dd0_9e62_d6a16580e0b5["setProp()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 5a792874_dbaf_1dd0_9e62_d6a16580e0b5
  25aca4ae_e70f_705d_7673_e44af72ab539["checkControlledValueProps()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 25aca4ae_e70f_705d_7673_e44af72ab539
  7fde30c4_2df7_4194_0c3e_083dd0f57c00["validateInputProps()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 7fde30c4_2df7_4194_0c3e_083dd0f57c00
  754de9fa_432c_542e_fa21_08b18b75915b["initInput()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 754de9fa_432c_542e_fa21_08b18b75915b
  c18a6119_e933_0faf_e206_a100b0cc50ec["validateSelectProps()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| c18a6119_e933_0faf_e206_a100b0cc50ec
  b1ff4c46_04e6_a98d_f699_7501486d125f["initSelect()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| b1ff4c46_04e6_a98d_f699_7501486d125f
  b12eb1de_52b7_7e30_8597_6e5ab493b767["validateTextareaProps()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| b12eb1de_52b7_7e30_8597_6e5ab493b767
  d7552454_ad8c_6921_661d_7d0abf4e6add["initTextarea()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| d7552454_ad8c_6921_661d_7d0abf4e6add
  2d1887fd_1055_7a9f_f81b_d9416d83bdab["validateOptionProps()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 2d1887fd_1055_7a9f_f81b_d9416d83bdab
  2085de17_2522_af25_8b8d_76ff7166552c["isCustomElement()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 2085de17_2522_af25_8b8d_76ff7166552c
  65717281_efda_4b8d_7a97_9947c26aa05e["setPropOnCustomElement()"]
  96cf114b_9b89_b174_432c_1584a973fcdd -->|calls| 65717281_efda_4b8d_7a97_9947c26aa05e
  style 96cf114b_9b89_b174_432c_1584a973fcdd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-dom-bindings/src/client/ReactDOMComponent.js lines 1089–1474

export function setInitialProperties(
  domElement: Element,
  tag: string,
  props: Object,
): void {
  if (__DEV__) {
    validatePropertiesInDevelopment(tag, props);
  }

  // TODO: Make sure that we check isMounted before firing any of these events.

  switch (tag) {
    case 'div':
    case 'span':
    case 'svg':
    case 'path':
    case 'a':
    case 'g':
    case 'p':
    case 'li': {
      // Fast track the most common tag types
      break;
    }
    // img tags previously were implemented as void elements with non delegated events however Safari (and possibly Firefox)
    // begin fetching the image as soon as the `src` or `srcSet` property is set and if we set these before other properties
    // that can modify the request (such as crossorigin) or the resource fetch (such as sizes) then the browser will load
    // the wrong thing or load more than one thing. This implementation ensures src and srcSet are set on the instance last
    case 'img': {
      listenToNonDelegatedEvent('error', domElement);
      listenToNonDelegatedEvent('load', domElement);
      // Mostly a port of Void Element logic with special casing to ensure srcset and src are set last
      let hasSrc = false;
      let hasSrcSet = false;
      for (const propKey in props) {
        if (!props.hasOwnProperty(propKey)) {
          continue;
        }
        const propValue = props[propKey];
        if (propValue == null) {
          continue;
        }
        switch (propKey) {
          case 'src':
            hasSrc = true;
            break;
          case 'srcSet':
            hasSrcSet = true;
            break;
          case 'children':
          case 'dangerouslySetInnerHTML': {
            // TODO: Can we make this a DEV warning to avoid this deny list?
            throw new Error(
              `${tag} is a void element tag and must neither have \`children\` nor ` +
                'use `dangerouslySetInnerHTML`.',
            );
          }
          // defaultChecked and defaultValue are ignored by setProp
          default: {
            setProp(domElement, tag, propKey, propValue, props, null);
          }
        }
      }
      if (hasSrcSet) {
        setProp(domElement, tag, 'srcSet', props.srcSet, props, null);
      }
      if (hasSrc) {
        setProp(domElement, tag, 'src', props.src, props, null);
      }
      return;
    }
    case 'input': {
      if (__DEV__) {
        checkControlledValueProps('input', props);
      }
      // We listen to this event in case to ensure emulated bubble
      // listeners still fire for the invalid event.
      listenToNonDelegatedEvent('invalid', domElement);

      let name = null;
      let type = null;
      let value = null;

Domain

Subdomains

Frequently Asked Questions

What does setInitialProperties() do?
setInitialProperties() is a function in the react codebase, defined in packages/react-dom-bindings/src/client/ReactDOMComponent.js.
Where is setInitialProperties() defined?
setInitialProperties() is defined in packages/react-dom-bindings/src/client/ReactDOMComponent.js at line 1089.
What does setInitialProperties() call?
setInitialProperties() calls 13 function(s): checkControlledValueProps, initInput, initSelect, initTextarea, isCustomElement, listenToNonDelegatedEvent, setProp, setPropOnCustomElement, and 5 more.

Analyze Your Own Codebase

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

Try Supermodel Free