<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Radin Vafaei</title>
    <description>The latest articles on DEV Community by Radin Vafaei (@radinvafaei).</description>
    <link>https://dev.to/radinvafaei</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F788655%2Fe48dd4e4-41d7-494a-a763-6e42faf54b54.png</url>
      <title>DEV Community: Radin Vafaei</title>
      <link>https://dev.to/radinvafaei</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/radinvafaei"/>
    <language>en</language>
    <item>
      <title>Why React Freeze Children in DEV mode?</title>
      <dc:creator>Radin Vafaei</dc:creator>
      <pubDate>Sun, 09 Jan 2022 02:06:43 +0000</pubDate>
      <link>https://dev.to/radinvafaei/why-react-freeze-children-in-dev-mode-3lcc</link>
      <guid>https://dev.to/radinvafaei/why-react-freeze-children-in-dev-mode-3lcc</guid>
      <description>&lt;p&gt;I've been reading react code base and understood react freeze children if it is on dev mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function createElement(type, config, children) {
  let propName;

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

  let key = null;
  let ref = null;
  let self = null;
  let source = null;

  if (config != null) {
    if (hasValidRef(config)) {
      ref = config.ref;

      if (__DEV__) {
        warnIfStringRefCannotBeAutoConverted(config);
      }
    }
    if (hasValidKey(config)) {
      if (__DEV__) {
        checkKeyStringCoercion(config.key);
      }
      key = '' + config.key;
    }

    self = config.__self === undefined ? null : config.__self;
    source = config.__source === undefined ? null : config.__source;
    // Remaining properties are added to a new props object
    for (propName in config) {
      if (
        hasOwnProperty.call(config, propName) &amp;amp;&amp;amp;
        !RESERVED_PROPS.hasOwnProperty(propName)
      ) {
        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 &amp;gt; 1) {
    const childArray = Array(childrenLength);
    for (let i = 0; i &amp;lt; childrenLength; i++) {
      childArray[i] = arguments[i + 2];
    }
    if (__DEV__) {
      if (Object.freeze) {
        Object.freeze(childArray);
      }
    }
    props.children = childArray;
  }

  // Resolve default props
  if (type &amp;amp;&amp;amp; type.defaultProps) {
    const defaultProps = type.defaultProps;
    for (propName in defaultProps) {
      if (props[propName] === undefined) {
        props[propName] = defaultProps[propName];
      }
    }
  }
  if (__DEV__) {
    if (key || ref) {
      const displayName =
        typeof type === 'function'
          ? type.displayName || type.name || 'Unknown'
          : type;
      if (key) {
        defineKeyPropWarningGetter(props, displayName);
      }
      if (ref) {
        defineRefPropWarningGetter(props, displayName);
      }
    }
  }
  return ReactElement(
    type,
    key,
    ref,
    self,
    source,
    ReactCurrentOwner.current,
    props,
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in fact I'm not able to understand why react use freeze method for childArray if it's environment been on the dev mode.&lt;br&gt;
can anybody explain it to me?&lt;br&gt;
thanks.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>createelement</category>
      <category>freeze</category>
    </item>
  </channel>
</rss>
