<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>React &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/react/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 16:17:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>React &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>React: Debugging Layout Thrashing</title>
		<link>https://myshittycode.com/2019/04/15/react-debugging-layout-thrashing/</link>
					<comments>https://myshittycode.com/2019/04/15/react-debugging-layout-thrashing/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Tue, 16 Apr 2019 02:04:56 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[React]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=1089</guid>

					<description><![CDATA[<p>PROBLEM When the React app grows larger over time, it is highly likely to run into situations where the component keeps re-rendering for no apparent reason. There are many reasons why this is happening&#8230; to name a few&#8230;. parent component re-renders, this.props or this.state has changed, etc. The key is to quickly find out what [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2019/04/15/react-debugging-layout-thrashing/">React: Debugging Layout Thrashing</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>When the React app grows larger over time, it is highly likely to run into situations where the component keeps re-rendering for no apparent reason.</p>



<p>There are many reasons why this is happening&#8230; to name a few&#8230;. parent component re-renders, <strong>this.props</strong> or <strong>this.state</strong> has changed, etc.</p>



<p>The key is to quickly find out what causes the component to re-render constantly.</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>The simplest solution, in my opinion, is to paste the following block into the troublesome component:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
componentDidUpdate(prevProps, prevState) {
  const debug = (label, currObject = {}, prevObject = {}) =&amp;gt; {
    Object.entries(currObject).forEach((&#x5B;key, currValue]) =&amp;gt; {
      if (prevObject&#x5B;key] !== currValue) {
        console.log(`&#x5B;DEBUG] ${label} has changed: `, key);
        console.log(&#039;&#x5B;DEBUG] - BEFORE : &#039;, prevObject&#x5B;key]);
        console.log(&#039;&#x5B;DEBUG] -  AFTER : &#039;, currValue);
      }
    });
  };

  debug(&#039;Prop&#039;, this.props, prevProps);
  debug(&#039;State&#039;, this.state, prevState);
}
</pre></div>


<p>Adding this <strong>componentDidUpdate(..)</strong> lifecycle allows us to quickly find out which property or state has changed.</p>



<p>When running the app, the console may display something like this:-</p>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="311" height="174" src="https://myshittycode.com/wp-content/uploads/2019/04/screen-shot-2019-04-15-at-8.31.50-pm-1.png?x45560" alt="Console Log" class="wp-image-1090" srcset="https://myshittycode.com/wp-content/uploads/2019/04/screen-shot-2019-04-15-at-8.31.50-pm-1.png 311w, https://myshittycode.com/wp-content/uploads/2019/04/screen-shot-2019-04-15-at-8.31.50-pm-1-300x168.png 300w" sizes="(max-width: 311px) 100vw, 311px" /></figure>



<p>The key is to look for identical object or array displayed in both &#8220;BEFORE&#8221; and &#8220;AFTER&#8221; statements. This shows that while the values look similar, they fail on strict equality check (&#8216;===&#8217;), which causes the component to re-render.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2019/04/15/react-debugging-layout-thrashing/">React: Debugging Layout Thrashing</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2019/04/15/react-debugging-layout-thrashing/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1089</post-id>	</item>
		<item>
		<title>React + Recompose: Calling Multiple HOC Wrappers</title>
		<link>https://myshittycode.com/2018/04/02/react-recompose-calling-multiple-hoc-wrappers/</link>
					<comments>https://myshittycode.com/2018/04/02/react-recompose-calling-multiple-hoc-wrappers/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Mon, 02 Apr 2018 17:37:35 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[ES6]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[React]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=1081</guid>

					<description><![CDATA[<p>PROBLEM Sometimes, wrapping a React component with multiple High Order Components (HOC) can get rather unwieldy and unreadable. For example:- SOLUTION To fix this, we can leverage recompose library. Now, we can rewrite the above example like this:- Keep in mind, the HOC order defined in compose(..) is important.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2018/04/02/react-recompose-calling-multiple-hoc-wrappers/">React + Recompose: Calling Multiple HOC Wrappers</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>Sometimes, wrapping a React component with multiple High Order Components (HOC) can get rather unwieldy and unreadable.</p>



<p>For example:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; highlight: [10]; title: ; notranslate">
import React from &#039;react&#039;;
import { withRouter } from &#039;react-router-dom&#039;;
import { withStyles } from &#039;material-ui/styles&#039;;
import withWidth from &#039;material-ui/utils/withWidth&#039;;

class MyComponent extends React.PureComponent {
	// ...
}

export default withRouter(withStyles(styles)(withWidth()(MyComponent)));
</pre></div>


<h2 class="wp-block-heading">SOLUTION</h2>



<p>To fix this, we can leverage <a href="https://github.com/acdlite/recompose" target="_blank" rel="noopener">recompose</a> library.</p>



<p>Now, we can rewrite the above example like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; highlight: [5,11,12,13,14,15]; title: ; notranslate">
import React from &#039;react&#039;;
import { withRouter } from &#039;react-router-dom&#039;;
import { withStyles } from &#039;material-ui/styles&#039;;
import withWidth from &#039;material-ui/utils/withWidth&#039;;
import compose from &#039;recompose/compose&#039;;

class MyComponent extends React.PureComponent {
	// ...
}

export default compose(
  withRouter,
  withStyles(styles),
  withWidth(),
)(MyComponent);
</pre></div>


<p>Keep in mind, the HOC order defined in <strong>compose(..)</strong> is important.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2018/04/02/react-recompose-calling-multiple-hoc-wrappers/">React + Recompose: Calling Multiple HOC Wrappers</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2018/04/02/react-recompose-calling-multiple-hoc-wrappers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1081</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-20 00:42:26 by W3 Total Cache
-->