<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Performance on Osmar Petry</title><link>https://osmarpetry.dev/tags/performance/</link><description>Recent content in Performance on Osmar Petry</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Wed, 15 Jan 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://osmarpetry.dev/tags/performance/rss.xml" rel="self" type="application/rss+xml"/><item><title>Optimizing React with Memoization</title><link>https://osmarpetry.dev/blog/react-optimizing-with-memoization/</link><pubDate>Wed, 15 Jan 2025 00:00:00 +0000</pubDate><guid>https://osmarpetry.dev/blog/react-optimizing-with-memoization/</guid><description>&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;&#10;&lt;p&gt;It’s important to understand the component lifecycle and when to re-render. Some tips to optimize React include:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Use useMemo or memo to memoize expensive calculations or component render.&lt;/li&gt;&#10;&lt;li&gt;Use useCallback to memoize callback functions.&lt;/li&gt;&#10;&lt;li&gt;Use React.PureComponent instead of React.Component for pure components.&lt;/li&gt;&#10;&lt;li&gt;Use shouldComponentUpdate lifecycle method to avoid unnecessary re-renders.&lt;/li&gt;&#10;&lt;li&gt;Avoid using the state for non-essential data that does not affect the render.&lt;/li&gt;&#10;&lt;li&gt;Avoid using too many inline functions and use memoized callback functions instead.&#10;It is important to note that the most important aspect of optimization is to understand the performance bottlenecks in your application and address them accordingly.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="usememo"&gt;useMemo&lt;/h2&gt;&#10;&lt;p&gt;This is a hook that is used to memoize a component&amp;rsquo;s expensive calculations. It helps to reduce the number of re-renders by only recalculating the value when one of its dependencies has changed. It takes two arguments, the first being a calculation function and the second being an array of dependencies. If the dependencies change, the calculation function will be re-executed, otherwise, the previously calculated value is returned, example:&lt;/p&gt;</description></item></channel></rss>