<?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: Leonardo Lemos</title>
    <description>The latest articles on DEV Community by Leonardo Lemos (@leo_lemos).</description>
    <link>https://dev.to/leo_lemos</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%2F1117930%2Fa1928d37-8034-4083-abd6-a94f8ee6fd76.jpeg</url>
      <title>DEV Community: Leonardo Lemos</title>
      <link>https://dev.to/leo_lemos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leo_lemos"/>
    <language>en</language>
    <item>
      <title>React.memo is not memoization</title>
      <dc:creator>Leonardo Lemos</dc:creator>
      <pubDate>Sun, 30 Jul 2023 16:34:13 +0000</pubDate>
      <link>https://dev.to/leo_lemos/reactmemo-is-not-memoization-4cpa</link>
      <guid>https://dev.to/leo_lemos/reactmemo-is-not-memoization-4cpa</guid>
      <description>&lt;p&gt;In a recent conversation with some colleagues at work, I suggested using &lt;code&gt;React.memo&lt;/code&gt; for a component we were building. However, one of my colleagues questioned whether this higher-order component (HOC) would provide any optimization benefits. It seems that many software engineers don't fully understand the memoization that React offers, so I wanted to clarify it in this post.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memoization is&lt;/strong&gt; the process of optimizing performance by caching the result of a computation and associating it with the parameter used to calculate it. However, &lt;strong&gt;React's version of memoization is different&lt;/strong&gt;. When a component is wrapped in &lt;code&gt;React.memo&lt;/code&gt;, React's reconciliation algorithm only compares the previous and current properties to determine whether to re-render the component. It doesn't cache all the properties passed to it or keep a history of properties to return instant results based on previous function calls. Instead, it only skips re-rendering a component if the props remain unchanged.&lt;/p&gt;

&lt;p&gt;While memoization can help optimize performance in some cases, it's not a one-size-fits-all solution. The React documentation cautions that memoization does not guarantee optimization, and I agree. Memoizing everything can lead to slower reconciliation due to an overload of comparisons. Therefore, &lt;code&gt;React.memo&lt;/code&gt; is most useful for pure function components or components that frequently re-render with the same props and output. &lt;em&gt;(Image below)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdbi6qx5dk5ocr3jooe3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdbi6qx5dk5ocr3jooe3m.png" alt="A small view of re-render process" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In conclusion&lt;/strong&gt;, technology is a trade-off, and there is no silver bullet for all problems. If you need to pass a function or complex data, other optimizations may be necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Credits &amp;amp; References&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Photo by &lt;a href="https://unsplash.com/@busgram?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Büşra Salkım&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-display-case-filled-with-lots-of-different-colored-macaroons-MidUI6QPiys?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://react.dev/reference/react/memo" rel="noopener noreferrer"&gt;memo – React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://react.dev/learn/keeping-components-pure" rel="noopener noreferrer"&gt;Keeping Components Pure – React&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://legacy.reactjs.org/docs/reconciliation.html" rel="noopener noreferrer"&gt;Reconciliation – React&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>performance</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
