<?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: alexandre-emmanuel</title>
    <description>The latest articles on DEV Community by alexandre-emmanuel (@alexandre-emmanuel).</description>
    <link>https://dev.to/alexandre-emmanuel</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%2F2092042%2Fd4a379be-7a0c-4ad2-ba1f-06aa44d12d01.png</url>
      <title>DEV Community: alexandre-emmanuel</title>
      <link>https://dev.to/alexandre-emmanuel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexandre-emmanuel"/>
    <language>en</language>
    <item>
      <title>How to track React re-renders - why-did-you-render issues</title>
      <dc:creator>alexandre-emmanuel</dc:creator>
      <pubDate>Wed, 18 Sep 2024 12:06:05 +0000</pubDate>
      <link>https://dev.to/alexandre-emmanuel/how-to-track-react-re-renders-why-did-you-render-issues-10gc</link>
      <guid>https://dev.to/alexandre-emmanuel/how-to-track-react-re-renders-why-did-you-render-issues-10gc</guid>
      <description>&lt;p&gt;I have written some parts of ERP-type React 18.2 web app that uses Redux, RTK, Material-UI, AgGrid. It has heavy forms (e.g. invoice form with header, invoice-lines, tax-lines and complex recaclulation logic). One of the important feature of my app is to allow multi-tab interface. There are several applications that allow to open several in-app forms at once - each within its own tab. Axelor ERP &lt;a href="https://demo.axelor.com/open-suite-en/" rel="noopener noreferrer"&gt;https://demo.axelor.com/open-suite-en/&lt;/a&gt; is one example. I am using &lt;a href="https://mui.com/material-ui/react-tabs/" rel="noopener noreferrer"&gt;https://mui.com/material-ui/react-tabs/&lt;/a&gt; dynamically.&lt;/p&gt;

&lt;p&gt;All that is very nice. But performace issues spring up, especially when multiple in-app tabs are being opened. And performance issues are, of course, due to rerender.&lt;/p&gt;

&lt;p&gt;It is very strange, that &lt;a href="https://react.dev/" rel="noopener noreferrer"&gt;https://react.dev/&lt;/a&gt; has very few information about importance of re-rendering optimization as this failure can kill whole projects.&lt;/p&gt;

&lt;p&gt;Several books address re-rendering optimization. The best ones are these two. &lt;a href="https://www.manning.com/books/react-in-depth" rel="noopener noreferrer"&gt;https://www.manning.com/books/react-in-depth&lt;/a&gt; has extensive and practical Ch.3 and this book/blog &lt;a href="https://www.developerway.com/tags/re-renders" rel="noopener noreferrer"&gt;https://www.developerway.com/tags/re-renders&lt;/a&gt; has even multiple chapters.&lt;/p&gt;

&lt;p&gt;But the strange thing is that these books and articles are excellent about techniques how to improve the optimization, but they almost nothing about the tools to monitor the re-renders and track down the causes and data changes of re-renders.&lt;/p&gt;

&lt;p&gt;React Developer Tools Profiler/Flamegraph is good in reporting the whole rerenders and giving short information 'Why did this render?' and 'Rendered at'. But that is not sufficient. Especially if one compares this with the legendary why-did-you-render.&lt;/p&gt;

&lt;p&gt;And now the confusions starts. &lt;a href="https://www.npmjs.com/package/@welldone-software/why-did-you-render" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/@welldone-software/why-did-you-render&lt;/a&gt; seems to be the best tool imaginable for tracking the causes of re-render. Indispensable tool. It reports 400k weekly downloads.&lt;/p&gt;

&lt;p&gt;Yet - its codesanbox examples target React 16. I tried to upgrade its codesandbox examples to React 18. They run as React applications, but no wdyr concole reports are generated. There are some issues that reports this problem, e.g. &lt;a href="https://github.com/welldone-software/why-did-you-render/issues/294" rel="noopener noreferrer"&gt;https://github.com/welldone-software/why-did-you-render/issues/294&lt;/a&gt; but generally the activity is almost nonexistant. Stackoveflow threads has only severl questions about wdyr.&lt;/p&gt;

&lt;p&gt;So - what are the best practices to track down and debug excessive re-renders in React 18 and React 19 and is why-did-you-render the right tool even today or are there any alternatives? Even Google is almost silent about all of this.&lt;/p&gt;

&lt;p&gt;p.s. I managed to get some log entries from wdyr, but I am not sure what components get reported and which ones - not. As I am developing React 18 (and looking forward to React 19), my components are exclusively functional. wdyr was developed in times when class component was the almost the only option.&lt;/p&gt;

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