<?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: Leandro Roggerone</title>
    <description>The latest articles on DEV Community by Leandro Roggerone (@leostereo).</description>
    <link>https://dev.to/leostereo</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F789790%2F093b61ac-d099-495b-b6e2-d7b8c2446481.jpeg</url>
      <title>DEV Community: Leandro Roggerone</title>
      <link>https://dev.to/leostereo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leostereo"/>
    <language>en</language>
    <item>
      <title>component process order</title>
      <dc:creator>Leandro Roggerone</dc:creator>
      <pubDate>Sun, 09 Apr 2023 20:09:51 +0000</pubDate>
      <link>https://dev.to/leostereo/component-process-order-497k</link>
      <guid>https://dev.to/leostereo/component-process-order-497k</guid>
      <description>&lt;p&gt;Hello , guys ... Im react beginner trying to understand rendering orden on nested components .. lets supose following structure and console output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from 'react'
import React from 'react'

export const Comp2 = () =&amp;gt; {
  console.log("from component 2")
  useEffect(() =&amp;gt; {
    console.log("from component 2 useEffect")
  })

  return (
    &amp;lt;&amp;gt;
    &amp;lt;div&amp;gt;Component 2&amp;lt;/div&amp;gt;
    &amp;lt;Comp3/&amp;gt;
    &amp;lt;/&amp;gt;
  )
}
export const Comp1 = () =&amp;gt; {
  console.log("from component 1");
  useEffect(() =&amp;gt; {
    console.log("from component 1 useEffect")
  })


  return (
    &amp;lt;&amp;gt;
    &amp;lt;div&amp;gt;Component 1&amp;lt;/div&amp;gt;
    &amp;lt;Comp2/&amp;gt;
    &amp;lt;/&amp;gt;
  )
}
export const Comp3 = () =&amp;gt; {
  const [count3 , setCount3] = useState(10)
  console.log("from component 3");
  useEffect(() =&amp;gt; {
      console.log("from component 3 useEffect")
    })

  return (
      &amp;lt;&amp;gt;
      &amp;lt;div&amp;gt;Comp3&amp;lt;/div&amp;gt;
      &amp;lt;button onClick={()=&amp;gt;{setCount3((count) =&amp;gt; count + 1)}} &amp;gt;increment counter3&amp;lt;/button&amp;gt;
      &amp;lt;span&amp;gt;{count3}&amp;lt;/span&amp;gt;
      &amp;lt;/&amp;gt;
    )
}

function App() {
  const [count1, setCount1] = useState(0)
  const [count2, setCount2] = useState(0)

  console.log("Starting  count1 / count2:", count1,count2);

  useEffect(() =&amp;gt; {
    console.log("from App useEffect")
  }, )

  return (
    &amp;lt;&amp;gt;
      &amp;lt;button onClick={()=&amp;gt;{setCount1((count) =&amp;gt; count + 1)}} &amp;gt;incrementar contador 1&amp;lt;/button&amp;gt;
      &amp;lt;span&amp;gt;{count1}&amp;lt;/span&amp;gt;
      &amp;lt;button onClick={()=&amp;gt;{setCount2((count) =&amp;gt; count + 1)}} &amp;gt;incrementar contador 2&amp;lt;/button&amp;gt;
      &amp;lt;span&amp;gt;{count2}&amp;lt;/span&amp;gt;
      &amp;lt;Comp1/&amp;gt;
    &amp;lt;/&amp;gt;
  )

}

export default App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After F5 on browser, Im recibing following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Starting  count1 / count2: 0 0
from component 1
from component 2
from component 3
from component 3 useEffect
from component 2 useEffect
from component 1 useEffect
from App useEffect
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have following thoughts:&lt;br&gt;
1 Components Processing order depends on nesting order.&lt;br&gt;
2 Why log lines are printed in order begging on the father component to deeper child ? &lt;br&gt;
3 Why log lines inside useEffect hooks are printed on reverse order? &lt;br&gt;
4 Incrementing counter 3 only triggers component 3 render...&lt;br&gt;
5 Incrementing counter 1 or 2 renders all nested components,How can I prevent this?&lt;/p&gt;

&lt;p&gt;Any brief explaination / document to read would be great.&lt;br&gt;
thanks.&lt;/p&gt;

</description>
      <category>react</category>
    </item>
  </channel>
</rss>
