<?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: Douglas Almeida</title>
    <description>The latest articles on DEV Community by Douglas Almeida (@douglas_almeida_05b0db1f9).</description>
    <link>https://dev.to/douglas_almeida_05b0db1f9</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%2F1976481%2Fd5ede8f2-3f42-4506-997e-d40e580e9ff8.jpg</url>
      <title>DEV Community: Douglas Almeida</title>
      <link>https://dev.to/douglas_almeida_05b0db1f9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/douglas_almeida_05b0db1f9"/>
    <language>en</language>
    <item>
      <title>How react's rendering flow works</title>
      <dc:creator>Douglas Almeida</dc:creator>
      <pubDate>Tue, 27 Aug 2024 19:52:33 +0000</pubDate>
      <link>https://dev.to/douglas_almeida_05b0db1f9/how-reacts-rendering-flow-works-57ke</link>
      <guid>https://dev.to/douglas_almeida_05b0db1f9/how-reacts-rendering-flow-works-57ke</guid>
      <description>&lt;p&gt;To create a healthy application, it's important to understand How react's rendering flow works, and what happens when a stage changes.&lt;/p&gt;

&lt;p&gt;This topic is quite expensive, but I will try to summarize this topic in a way that you can understand.&lt;/p&gt;

&lt;p&gt;Let's start!&lt;/p&gt;

&lt;h3&gt;
  
  
  Flow stages
&lt;/h3&gt;

&lt;p&gt;The flow basically happens in three stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Trigger a render&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React renders your components&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React commits changes to the dom&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatqkuuuzavoe088nw814.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatqkuuuzavoe088nw814.png" alt="Diagram" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go through each one.&lt;/p&gt;

&lt;p&gt;Have you ever wondered what the meaning of this code is?&lt;/p&gt;

&lt;p&gt;Basically, it's the entry point of our application usually meaning &lt;code&gt;main.tsx&lt;/code&gt; or &lt;code&gt;index.tsx&lt;/code&gt;, this file is responsible for initial rendering, "React will establish a root for the domNode and handle the DOM management within it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1tvnzly6awcvnvqdvxe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1tvnzly6awcvnvqdvxe.png" alt="Main file" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjwciq0y9j4kbmiksmpc8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjwciq0y9j4kbmiksmpc8.png" alt="HTML example" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; component is our root component, all our flow needs to go through it, Routes, Providers and etc...&lt;/p&gt;

&lt;p&gt;The first rendering will be based on this guy.&lt;/p&gt;

&lt;p&gt;Ok, now we know how to work initial render, let's understand when react re-rendering a component.&lt;/p&gt;

&lt;h4&gt;
  
  
  React will re-rendering a component in three situations:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Hooks Changed (useState, Context, useReducer, UseEffect and etc..)&lt;/li&gt;
&lt;li&gt;Props Changed&lt;/li&gt;
&lt;li&gt;Parent Component re-rendered&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  When it happens React will:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Recreate HTML of this component&lt;/li&gt;
&lt;li&gt;Will Compare with the old version&lt;/li&gt;
&lt;li&gt;If something changes, it will &lt;strong&gt;rewrite/commit&lt;/strong&gt; HTML on the screen (React won't unmount and mount component again, re-render will only modify what changes in the component).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This whole process isn't done directly in real DOM, because it could be&lt;br&gt;
slow and costly in terms of performance, react uses &lt;strong&gt;VIRTUAL DOM&lt;/strong&gt; and the guy responsible for these calculations it's called &lt;strong&gt;RECONCILIATION&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Virtual DOM:&lt;/strong&gt; The Virtual DOM is a lightweight copy of the real DOM used by React.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reconciliation/Diffing Algorithm:&lt;/strong&gt; React compares the current Virtual DOM with the previous one to identify changes (diffs), Based on these differences, React efficiently determines the necessary updates to the real DOM, targeting only the changed parts.&lt;/p&gt;

&lt;p&gt;If you install and use &lt;a href="https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi" rel="noopener noreferrer"&gt;React Devtools&lt;/a&gt; you will be able to understand the entire process of your component rendering, in the profile you can click on the blue point on the left and it will record for you what's happened with the components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgmgvqm0p11j890do30b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgmgvqm0p11j890do30b.png" alt="React Dev Tools1" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fako34c8o6mrpe2zk8vgt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fako34c8o6mrpe2zk8vgt.png" alt="React Dev Tools2" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsmgactqoeie7ycga01j0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsmgactqoeie7ycga01j0.png" alt="React Dev Tools3" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's see one example&lt;/p&gt;

&lt;p&gt;I have my &lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; root component and a simple Container with an input and Counter Component inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Container } from './Container'

const App = () =&amp;gt; {
  return (
    &amp;lt;div
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        height: '100vh',
      }}
    &amp;gt;
      &amp;lt;Container /&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'
import { Input } from './components/ui/input'
import { Counter } from './Counter'

export const Container = () =&amp;gt; {
  const [inputValue, setInputValue] = useState('')

  return (
    &amp;lt;div
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        gap: '20px',
        width: '300px',
      }}
    &amp;gt;
      &amp;lt;h1&amp;gt;Root Component&amp;lt;/h1&amp;gt;
      &amp;lt;Input
        type="text"
        value={inputValue}
        onChange={(e) =&amp;gt; setInputValue(e.target.value)}
        style={{
          width: '200px',
        }}
      /&amp;gt;
      &amp;lt;span&amp;gt;
        Lorem ipsum dolor sit amet, 
        consectetur adipisicing elit. Ipsum deleniti
        eum eveniet a neque dolores, 
        facilis est consectetur numquam blanditiis
        illum nam tenetur eius expedita laborum? 
        Hic praesentium inventore sunt?
      &amp;lt;/span&amp;gt;

      &amp;lt;Counter /&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'
import { Button } from './components/ui/button'

export const Counter = () =&amp;gt; {
  const [count, setCount] = useState(0)

  return (
    &amp;lt;div
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        gap: '20px',
      }}
    &amp;gt;
      &amp;lt;span&amp;gt;{count}&amp;lt;/span&amp;gt;

      &amp;lt;Button
        style={{
          width: '100%',
        }}
        onClick={() =&amp;gt; setCount(count + 1)}
      &amp;gt;
        +
      &amp;lt;/Button&amp;gt;
      &amp;lt;Button
        style={{
          width: '100%',
        }}
        onClick={() =&amp;gt; setCount(count - 1)}
      &amp;gt;
        _
      &amp;lt;/Button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's enable a feature in React dev Tools, with which we can see highlight updates when components are re-rendered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpv9rmzb1oqqdbd34rjmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpv9rmzb1oqqdbd34rjmw.png" alt="React DevTool Highlights" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the first case, we'll click on the &lt;strong&gt;&lt;/strong&gt; component button to increase the counter value, as you can see, only it is being re-rendered again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1eA3hxfW6yR4mlJHnj/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1eA3hxfW6yR4mlJHnj/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It happens because in this case, we are just updating the component, every time we click on the increase button, this event handler is called onClick={() =&amp;gt; setCount(count + 1)} , and the counter state is updated.&lt;/p&gt;

&lt;p&gt;All the steps I explained above take place in this quick process.&lt;/p&gt;

&lt;p&gt;Now we'll type something in our input within the  Component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/a69BwVPfA8RUX0NknO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/a69BwVPfA8RUX0NknO/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, the component is being re-rendered because we are updating inputValue state every time we type something in the input, but the Counter component is being re-rendered too, it's happening because Counter is children from Container, and when the parent component is re-rendered, the children are also.&lt;/p&gt;

&lt;p&gt;We have some resources in react to avoid this behavior in certain situations, using the &lt;code&gt;memo&lt;/code&gt;, but I'll talk about that in another post.&lt;/p&gt;

&lt;p&gt;That's all for today guys! I hope you liked the content, leave your feedback.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How react's rendering flow works</title>
      <dc:creator>Douglas Almeida</dc:creator>
      <pubDate>Tue, 27 Aug 2024 17:46:48 +0000</pubDate>
      <link>https://dev.to/douglas_almeida_05b0db1f9/how-to-avoid-using-unnecessary-useeffect-in-your-react-app-4nlp</link>
      <guid>https://dev.to/douglas_almeida_05b0db1f9/how-to-avoid-using-unnecessary-useeffect-in-your-react-app-4nlp</guid>
      <description>&lt;p&gt;To create a healthy application, it's important to understand How react's rendering flow works, and what happens when a stage changes.&lt;/p&gt;

&lt;p&gt;This topic is quite expensive, but I will try to summarize this topic in a way that you can understand.&lt;/p&gt;

&lt;p&gt;Let's start!&lt;/p&gt;

&lt;h3&gt;
  
  
  Flow stages
&lt;/h3&gt;

&lt;p&gt;The flow basically happens in three stages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Trigger a render&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React renders your components&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React commits changes to the dom&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatqkuuuzavoe088nw814.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatqkuuuzavoe088nw814.png" alt="Diagram" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's go through each one.&lt;/p&gt;

&lt;p&gt;Have you ever wondered what the meaning of this code is?&lt;/p&gt;

&lt;p&gt;Basically, it's the entry point of our application usually meaning main.tsx or index.tsx, this file is responsible for initial rendering, "React will establish a root for the domNode and handle the DOM management within it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1tvnzly6awcvnvqdvxe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1tvnzly6awcvnvqdvxe.png" alt="Main file" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjwciq0y9j4kbmiksmpc8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjwciq0y9j4kbmiksmpc8.png" alt="HTML example" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; component is our root component, all our flow needs to go through it, Routes, Providers and etc...&lt;/p&gt;

&lt;p&gt;The first rendering will be based on this guy.&lt;/p&gt;

&lt;p&gt;Ok, now we know how to work initial render, let's understand when react re-rendering a component.&lt;/p&gt;

&lt;h4&gt;
  
  
  React will re-rendering a component in three situations:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Hooks Changed (useState, Context, useReducer, UseEffect and etc..)&lt;/li&gt;
&lt;li&gt;Props Changed&lt;/li&gt;
&lt;li&gt;Parent Component re-rendered&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  When it happens React will:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Recreate HTML of this component&lt;/li&gt;
&lt;li&gt;Will Compare with the old version&lt;/li&gt;
&lt;li&gt;If something changes, it will &lt;strong&gt;rewrite/commit&lt;/strong&gt; HTML on the screen (React won't unmount and mount component again, re-render will only modify what changes in the component).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This whole process isn't done directly in real DOM, because it could be&lt;br&gt;
slow and costly in terms of performance, react uses &lt;strong&gt;VIRTUAL DOM&lt;/strong&gt; and the guy responsible for these calculations it's called &lt;strong&gt;RECONCILIATION&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Virtual DOM:&lt;/strong&gt; The Virtual DOM is a lightweight copy of the real DOM used by React. It allows React to efficiently update the UI by comparing the current and previous versions of the Virtual DOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reconciliation/Diffing Algorithm:&lt;/strong&gt; React compares the current Virtual DOM with the previous one to identify changes (diffs), Based on these differences, React efficiently determines the necessary updates to the real DOM, targeting only the changed parts.&lt;/p&gt;

&lt;p&gt;If you install and use &lt;a href="https://chromewebstore.google.com/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi" rel="noopener noreferrer"&gt;React Devtools&lt;/a&gt; you will be able to understand the entire process of your component rendering, in the profile you can click on the blue point on the left and it will record for you what's happened with the components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgmgvqm0p11j890do30b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgmgvqm0p11j890do30b.png" alt="React Dev Tools1" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fako34c8o6mrpe2zk8vgt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fako34c8o6mrpe2zk8vgt.png" alt="React Dev Tools2" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsmgactqoeie7ycga01j0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsmgactqoeie7ycga01j0.png" alt="React Dev Tools3" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's see one example&lt;/p&gt;

&lt;p&gt;I have my root component and a simple Container with a input and Counter Component inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Container } from './Container'

const App = () =&amp;gt; {
  return (
    &amp;lt;div
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        height: '100vh',
      }}
    &amp;gt;
      &amp;lt;Container /&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'
import { Input } from './components/ui/input'
import { Counter } from './Counter'

export const Container = () =&amp;gt; {
  const [inputValue, setInputValue] = useState('')

  return (
    &amp;lt;div
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        gap: '20px',
        width: '300px',
      }}
    &amp;gt;
      &amp;lt;h1&amp;gt;Root Component&amp;lt;/h1&amp;gt;
      &amp;lt;Input
        type="text"
        value={inputValue}
        onChange={(e) =&amp;gt; setInputValue(e.target.value)}
        style={{
          width: '200px',
        }}
      /&amp;gt;
      &amp;lt;span&amp;gt;
        Lorem ipsum dolor sit amet, 
        consectetur adipisicing elit. Ipsum deleniti
        eum eveniet a neque dolores, 
        facilis est consectetur numquam blanditiis
        illum nam tenetur eius expedita laborum? 
        Hic praesentium inventore sunt?
      &amp;lt;/span&amp;gt;

      &amp;lt;Counter /&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react'
import { Button } from './components/ui/button'

export const Counter = () =&amp;gt; {
  const [count, setCount] = useState(0)

  return (
    &amp;lt;div
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        gap: '20px',
      }}
    &amp;gt;
      &amp;lt;span&amp;gt;{count}&amp;lt;/span&amp;gt;

      &amp;lt;Button
        style={{
          width: '100%',
        }}
        onClick={() =&amp;gt; setCount(count + 1)}
      &amp;gt;
        +
      &amp;lt;/Button&amp;gt;
      &amp;lt;Button
        style={{
          width: '100%',
        }}
        onClick={() =&amp;gt; setCount(count - 1)}
      &amp;gt;
        _
      &amp;lt;/Button&amp;gt;
    &amp;lt;/div&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's enable a feature in React dev Tools, with which we can see highlight updates when components are re-rendered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpv9rmzb1oqqdbd34rjmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpv9rmzb1oqqdbd34rjmw.png" alt="React DevTool Highlights" width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the first case, we'll click on the &lt;strong&gt;&lt;/strong&gt; component button to increase the counter value, as you can see, only it is being re-rendered again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1eA3hxfW6yR4mlJHnj/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1eA3hxfW6yR4mlJHnj/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It happens because in this case, we are just updating the component, every time we click on the increase button, this event handler is called onClick={() =&amp;gt; setCount(count + 1)} , and the counter state is updated.&lt;/p&gt;

&lt;p&gt;All the steps I explained above take place in this quick process.Now we'll type something in our input within the  Component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/a69BwVPfA8RUX0NknO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/a69BwVPfA8RUX0NknO/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, the component is being re-rendered because we are updating inputValue state every time we type something in the input, but the component is being re-rendered too, it's happening because Counter is children from Container, and when the parent component is re-rendered, the children are also.&lt;/p&gt;

&lt;p&gt;We have some resources in react to avoid this behavior in certain situations, using the &lt;code&gt;memo&lt;/code&gt;, but I'll talk about that in another post.&lt;/p&gt;

&lt;p&gt;That's all for today guys! I hope you liked the content, leave your feedback.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
