{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/2020-07-11","result":{"data":{"markdownRemark":{"html":"<p><em>Optimization is fun because it's not necessary.</em> - Brad Fitzpatrick</p>\n<p>While I don't necessarily agree with this statement in a strict sense, I do understand the point that Fitzpatrick is trying to make. Over optimization is a trap that the programmer needs to\nconstantly be on the lookout for, but that doesn't mean that we shouldn't make informed decisions upfront about architecture, standards, and strategies to make our apps as performant as possible.\nPutting in a timeboxed spike upfront can be an effective way to avoid pitfalls and \"gotchas\" when approaching a new feature or project, as it allows us to get a lay of the land and and forces\nus to look at exactly what we're trying to accomplish. This way we establish a scope and then we can always iterate and optimize as we get further into development.</p>\n<p>When it comes to React, there\naren't many things we need to worry about upfront, in terms of performance. The use of the virtual DOM means that even the most inefficient React app still tends to be relatively performant. But the\none area where React doesn't take any chances is the component render lifecycle. Our friends at Facebook want to make sure that our UIs are always up to date, even if it means that we waste render cycles\nthat are redundant or unnecessary. Luckily, React gives us several ways to help prune down unnecessary calls to a component's <code>render</code> method. Typically, this is done using the <code>shouldComponentUpdate</code> method,\nbut if we know that we never want to re-render a component unless the props or state changes then we can use <a href=\"https://reactjs.org/docs/react-api.html#reactpurecomponent\">Pure Components</a>.</p>\n<h2>A Little Bit of Context</h2>\n<p>Before getting started, let's understand what happens when our components get updated. The component lifecycle has two phases: <strong>render</strong> and <strong>commit</strong>. The render phase is when the <code>render</code> method on the\ncomponent is called and the output is compared with the last copy on the virtual DOM (this process is called <a href=\"https://reactjs.org/docs/reconciliation.html\">Reconciliation</a>). The commit phase is when React updates the DOM with the determined changes and then invokes the lifecycle handler,\nlike <code>componentDidUpdate</code>. If we look at the React docs, we see that this render cycle gets kicked off anytime one of the following happens:</p>\n<ol>\n<li>“state” values are updated</li>\n<li>“props” values are updated</li>\n<li><code>this.forceUpdate()</code> is called</li>\n</ol>\n<p>Now, there is an additional case that is often overlooked. When React decides that a component needs to be updated, that means that it plans to re-render <strong>the entire subtree of that component</strong>. This\nmeans that all the child components will be re-rendered, along with the parent. So, let's update our list to make this clear:</p>\n<ol>\n<li>“state” values are updated</li>\n<li>“props” values are updated</li>\n<li><code>this.forceUpdate()</code> is called</li>\n<li><strong>any of the above happen in a parent component</strong></li>\n</ol>\n<p>To be as explicit as possible, let's walk through exactly what happens when one of these cases is true.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 689px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/8edddd60dc7cdfb723f59885a3b0fa8e/0f79a/react-lifecycle.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 132.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAaCAYAAAC3g3x9AAAACXBIWXMAAAsSAAALEgHS3X78AAADNElEQVRIx41V2VYaQRD1/z8mJ3kyKjiACBpN1JgIyDL7vsKQ58q9DTMMxHB4uFM91dW3lq7uPlutVrJcLoUyyzIJw1DKspQ4jsUwDDFNU3RdlzzPlV0QBLV9JZs4a04URSG+7ysyEruuWyOKIoVDwkPys4q5OUFiSkZM8soZ0SQ6xD8RUjIykhCMyPM8SZKk/q8cfASuP2uys06s2Ww2k9FoJJPJBBjLeDwWy7LEcRwl6SBN09pJ9b8XYbkqlSIIQhUVQQLbdlBDT3zPV/UNwwj2u9JU5SF5HaHa4TyFp0jyIoVRislM0oyb46kx9flWXwDLZbGXLqNsEJbihm8yt25EdwZiB/dih9/E8IYyt/tqTJ3l34kTPUiQfUcAPtat63LVhKsVa1hKUswkyB+w+E50ty8zsyNTU5PxogXSrsysLhz01XyQPUhWeMcJ43yqDK1gWMP0B4q8qdsQPu4REh8T5o/1IoKEBgid6F79c47jMCehj41cC9d/nHI+Ez9FrULWCrWzekizJwv7RuFd1xSZ6dPhUKLYws6mdduwf7dtsyGM8on4GciCgZjBrYLh90X3brb/fSXtaKjs0tyVFdZxt6sD0YiQRwv9VbiQQO4omaVo4tiA3oNup6dk+2xaZpNyTcjPGoopGvp2bsiTF8qvJJdX4CVM5CmI1Pg1zjbA+BnSz3K1rtrlHSF+1hj8jhPRoGzjdLRwOtqOK5emJecLXY2pu7Jt0XBqNJwWM83kzzHCMc5iF1F2sHgA8ov5Qi5AdmWYcj6bSwtymKSigbgHQgs30dEIRzDuwvDasuUai4g2xiSs/gkNDntRfBohPWtIUwMR0QbZFaJkVMoR0GGEpxAy5Y4fSA+3M0k+P7/Il5ef8unHk5xP3uXr+1S6qF8HpCel/Ibm7MCQabYQZZXupW7UOoIpdxDh/zelUuBydeDVpYSxg7YwccfpfFtq3WbehkxxD5Yk3F5fu8beHm5OljzkvOajUMkQF6qLVkniaKPHogyZMNXVwXtSPV4q5SrKFJ45wftRPVKMDDVVtzNt8LwaeCJ4mzOiClzTOMv7zygneeAPjZs4+kgdPqOn4Ngz+he+eYzIwxtwYwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"React Lifecycle Flowchart\"\n        title=\"React Lifecycle Flowchart\"\n        src=\"/static/8edddd60dc7cdfb723f59885a3b0fa8e/0f79a/react-lifecycle.png\"\n        srcset=\"/static/8edddd60dc7cdfb723f59885a3b0fa8e/772e8/react-lifecycle.png 200w,\n/static/8edddd60dc7cdfb723f59885a3b0fa8e/e17e5/react-lifecycle.png 400w,\n/static/8edddd60dc7cdfb723f59885a3b0fa8e/0f79a/react-lifecycle.png 689w\"\n        sizes=\"(max-width: 689px) 100vw, 689px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<p>As shown in the diagram, we can use <code>shouldComponentUpdate</code> (or the equivalent when using Hooks in functional components) to bypass the render lifecycle altogether. This means that we avoid all the overhead\nof the diffing algorithm used during the reconciliation. It is a smarter and more efficient way for us to directly tell React \"no need to bother figuring out if this component needs re-rendered - it doesn't.\"\nBut the React developers figured out that in many cases, we never want to re-render our component if the props haven't changed - the output is always driven entirely by the inputs, hence the name \"pure\" components. We could write <code>shouldComponentUpdate</code> methods that compare all the props\nfor each of our components, but that sounds like a lot of work. If only there was a standard way to encapsulate that behavior for all of our simpler components...</p>\n<h2>Pure Components</h2>\n<p><code>PureComponent</code>s do not re-render when the props and/or state have been updated with the same values. They provide the same interface as a standard <code>Component</code>, except that the <code>shouldComponentUpdate</code> method\nis implemented for us with a shallow comparison of the state and props. Note that this is a shallow comparison, meaning that non-primitives will be compared by reference. There are ways to handle this that\nmay be covered in a future post. A <code>PureComponent</code> can be implemented as follows:</p>\n<pre><code class=\"language-javascript\">import React, { PureComponent } from \"react\";\n\nclass Pure extends PureComponent {\n  render() {\n    return &#x3C;div />;\n  }\n}\n\nexport default Pure;\n</code></pre>\n<p>Simple enough. But what about functional components? Not to fear, React gives us an HOC called <a href=\"https://reactjs.org/docs/react-api.html#reactmemo\"><code>memo</code></a> that we can use to make our functional components pure using memoization.\nA pure functional component might look something like:</p>\n<pre><code class=\"language-javascript\">import React, { memo } from \"react\";\n\nconst Pure = () => {\n  return &#x3C;div />;\n};\n\nexport default memo(Pure);\n</code></pre>\n<p>Let's look at some concrete examples to tie this off. Suppose we have an app with a simple <code>Counter</code> component that takes a prop <code>count</code> and displays the count in a <code>&#x3C;p></code> tag. A bit contrived, but it'll do.\nNow, let's say that the <code>count</code> prop is driven by the state of a parent <code>App</code> component, and the count is incremented each time we press a button.</p>\n<p>Our <code>App</code> would look like:</p>\n<pre><code class=\"language-javascript\">import React, { useState } from \"react\";\nimport \"./App.css\";\n\nimport Counter from \"./Counter\";\n\nfunction App() {\n  const [count, setCount] = useState(0);\n  return (\n    &#x3C;div className=\"App\">\n      &#x3C;Counter count={count} />\n      &#x3C;button onClick={() => setCount(count + 1)}>Increment&#x3C;/button>\n    &#x3C;/div>\n  );\n}\n\nexport default App;\n</code></pre>\n<p>And our <code>Counter</code> would look like:</p>\n<pre><code class=\"language-javascript\">import React from \"react\";\n\nconst Counter = ({ count }) => {\n  return &#x3C;p>{count}&#x3C;/p>;\n};\n\nexport default Counter;\n</code></pre>\n<p>We can use the Profiler React Dev Tool to analyze the render lifecycle when we increment the count.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 800px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/89b00f7eb817c9ada5c474cc66643760/4a70a/normal-count-profile.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 12.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAtklEQVQI123KPU+DUBjFcb6JnYQEooaXCxS5F5sKURuakE7VxZfYAG44OIk0Tv3S/94Sm3Rw+OWcnOcxVDLlWstvFLNMUlYVRZGjkpi5Sol8l9C9QmhpJJgKQS4Dho3A9WMckWFfhiPL8THev55o+hfq72ean1fqP+Omtbq3w9vocB9/ep2/G+5XJbf5kuKhQs7usC8ExrmXYgYSSzvmaTf/YQUK00uwswXyc4f42HK27pg8duwBsdhvMGiF2gYAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Render profile for normal count\"\n        title=\"Render profile for normal count\"\n        src=\"/static/89b00f7eb817c9ada5c474cc66643760/5a190/normal-count-profile.png\"\n        srcset=\"/static/89b00f7eb817c9ada5c474cc66643760/772e8/normal-count-profile.png 200w,\n/static/89b00f7eb817c9ada5c474cc66643760/e17e5/normal-count-profile.png 400w,\n/static/89b00f7eb817c9ada5c474cc66643760/5a190/normal-count-profile.png 800w,\n/static/89b00f7eb817c9ada5c474cc66643760/c1b63/normal-count-profile.png 1200w,\n/static/89b00f7eb817c9ada5c474cc66643760/29007/normal-count-profile.png 1600w,\n/static/89b00f7eb817c9ada5c474cc66643760/4a70a/normal-count-profile.png 2390w\"\n        sizes=\"(max-width: 800px) 100vw, 800px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<p>We can see that the <code>Counter</code> is re-rendered because the props changed. Nothing to see here. Even if we were using pure components, we would see the same behavior because the component obviously needs to\nre-render.</p>\n<p>Now, let's update our component so that, even when the parent's state changes, it's props do not. We can accomplish this by simply setting the <code>count</code> prop being passed in to always be <code>0</code>.</p>\n<pre><code class=\"language-javascript\">import React, { useState } from \"react\";\nimport \"./App.css\";\n\nimport Counter from \"./Counter\";\n\nfunction App() {\n  const [count, setCount] = useState(0);\n  return (\n    &#x3C;div className=\"App\">\n      &#x3C;Counter count={0} />\n      &#x3C;button onClick={() => setCount(count + 1)}>Increment&#x3C;/button>\n    &#x3C;/div>\n  );\n}\n\nexport default App;\n</code></pre>\n<p>In this new contrived example, we never need our <code>Counter</code> component to re-render, even when the parent's state changes and a re-render is triggered for the parent. But when we look at the Profiler in this\ncase, we see something unexpected.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 800px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/c4a5f13af829cd79d5e974db8502a4ab/a5262/parent-render-count.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 12%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAACCAYAAABYBvyLAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAjUlEQVQI1yXHywqCUABFUX+mQRb0IkpB82qpedX0mqUGQUGvcX/Qj++0Bouzj+YGAhk5yHRDrgJUKWmuFdk+QrVfxgI/sAhDmyT1iKTL5+1hixVzc41hOowmS/r6FH04Q/OPCfGlILsdyJ81+aMma/27QrVbvJqfrjvx/YTYZXjqjBGVjN2UgbWlt/D4Aqd0S73U4cJqAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Render profile for count when parent updates\"\n        title=\"Render profile for count when parent updates\"\n        src=\"/static/c4a5f13af829cd79d5e974db8502a4ab/5a190/parent-render-count.png\"\n        srcset=\"/static/c4a5f13af829cd79d5e974db8502a4ab/772e8/parent-render-count.png 200w,\n/static/c4a5f13af829cd79d5e974db8502a4ab/e17e5/parent-render-count.png 400w,\n/static/c4a5f13af829cd79d5e974db8502a4ab/5a190/parent-render-count.png 800w,\n/static/c4a5f13af829cd79d5e974db8502a4ab/c1b63/parent-render-count.png 1200w,\n/static/c4a5f13af829cd79d5e974db8502a4ab/29007/parent-render-count.png 1600w,\n/static/c4a5f13af829cd79d5e974db8502a4ab/a5262/parent-render-count.png 2388w\"\n        sizes=\"(max-width: 800px) 100vw, 800px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<p>It looks like the child <code>Counter</code> component re-rendered even though we didn't need it to. Again, this is because the entire component subtree is re-rendered by default anytime an update is triggered for\na component. But we can solve this with pure components.</p>\n<p>Now, let's say we have a <code>PureCounter</code> component that uses React Memo.</p>\n<pre><code class=\"language-javascript\">import React, { memo } from \"react\";\n\nconst PureCounter = ({ count }) => {\n  return &#x3C;p>{count}&#x3C;/p>;\n};\n\nexport default memo(PureCounter);\n</code></pre>\n<p>And we implement that component in the main <code>App</code>.</p>\n<pre><code class=\"language-javascript\">import React, { useState } from \"react\";\nimport \"./App.css\";\n\nimport PureCounter from \"./PureCounter\";\n\nfunction App() {\n  const [count, setCount] = useState(0);\n  return (\n    &#x3C;div className=\"App\">\n      &#x3C;PureCounter count={count} />\n      &#x3C;button onClick={() => setCount(count + 1)}>Increment&#x3C;/button>\n    &#x3C;/div>\n  );\n}\n\nexport default App;\n</code></pre>\n<p>If we look at the standard example using <code>PureCounter</code> in the Profiler, it looks exactly the same as the normal <code>Counter</code>. This is because in both cases the components actually need re-rendered when the count changes.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 800px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/6603c30aefe8c7ca788ff39c9dc26864/eadfb/pure-count-normal.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 12%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAACCAYAAABYBvyLAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAiklEQVQI1y2I7Q6BUABAexlMw2xkFtKNuip1l+hjU5vNn/jlETz5kfhxdnaOtvNsQn9LEDokykUlEnUOiWKX9CQJAxvprTjIDdFRdP1+OVi2xXztsTQF44nBYDhFH83QVBGQ3RR5S3lPqB4Z12f+c3PpXLdd/9+XsilwVcw+qTD9FN106RmC/kLwAYVAS5amrM2hAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Render profile for normal pure count\"\n        title=\"Render profile for normal pure count\"\n        src=\"/static/6603c30aefe8c7ca788ff39c9dc26864/5a190/pure-count-normal.png\"\n        srcset=\"/static/6603c30aefe8c7ca788ff39c9dc26864/772e8/pure-count-normal.png 200w,\n/static/6603c30aefe8c7ca788ff39c9dc26864/e17e5/pure-count-normal.png 400w,\n/static/6603c30aefe8c7ca788ff39c9dc26864/5a190/pure-count-normal.png 800w,\n/static/6603c30aefe8c7ca788ff39c9dc26864/c1b63/pure-count-normal.png 1200w,\n/static/6603c30aefe8c7ca788ff39c9dc26864/29007/pure-count-normal.png 1600w,\n/static/6603c30aefe8c7ca788ff39c9dc26864/eadfb/pure-count-normal.png 2386w\"\n        sizes=\"(max-width: 800px) 100vw, 800px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<p>But now let's look what happens when we set the <code>count</code> prop to always be <code>0</code> like we did for the second example with the normal <code>Counter</code>.</p>\n<pre><code class=\"language-javascript\">import React, { useState } from \"react\";\nimport \"./App.css\";\n\nimport PureCounter from \"./PureCounter\";\n\nfunction App() {\n  const [count, setCount] = useState(0);\n  return (\n    &#x3C;div className=\"App\">\n      &#x3C;PureCounter count={0} />\n      &#x3C;button onClick={() => setCount(count + 1)}>Increment&#x3C;/button>\n    &#x3C;/div>\n  );\n}\n\nexport default App;\n</code></pre>\n<p>And when we look at the Profiler.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 800px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/367b0412141e1c52b52dd6592adc9adb/18d85/pure-count-better.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 12.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA3ElEQVQI103MPUsCYQDA8fselRK9aCR6ds/DKXaidyjny4l2aMhVmC0hCKXI3dTSEA66CE1NtbQF2tDiZ/sritDwW39Ko2zg3dToPba59Sq06jlatSzNNc81cQqSsnmx0SilsHNJqpbKe6Bj5jNE1QzncUlMTRGNCZTedZLBncB/kPhdSXAvCLpbfkfj7cliGlSY+CXGwyKLjz5/n0NmL3WajoFpu9hVFyNvr0OJcnAi2D/W2DvaEf9ohCM6h2dpQqc6kUSWr+85P79LnKsOofgl1mhMuv9KuP28sQLwlXHzHc3EUQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Render profile for normal pure count\"\n        title=\"Render profile for normal pure count\"\n        src=\"/static/367b0412141e1c52b52dd6592adc9adb/5a190/pure-count-better.png\"\n        srcset=\"/static/367b0412141e1c52b52dd6592adc9adb/772e8/pure-count-better.png 200w,\n/static/367b0412141e1c52b52dd6592adc9adb/e17e5/pure-count-better.png 400w,\n/static/367b0412141e1c52b52dd6592adc9adb/5a190/pure-count-better.png 800w,\n/static/367b0412141e1c52b52dd6592adc9adb/c1b63/pure-count-better.png 1200w,\n/static/367b0412141e1c52b52dd6592adc9adb/29007/pure-count-better.png 1600w,\n/static/367b0412141e1c52b52dd6592adc9adb/18d85/pure-count-better.png 2382w\"\n        sizes=\"(max-width: 800px) 100vw, 800px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n  </a>\n    </span></p>\n<p>Look at that! Our <code>PureCounter</code> component didn't re-render, like we wanted. This, again, is because <code>memo</code> is automatically determining that the component does not need to be re-rendered due to the\nfact that the <code>count</code> prop didn't change.</p>\n<p>You can imagine how many redundant renders are being done in your component tree if you're not handling these cases. The larger the components, the more apparent it will be. So, do yourself a favor and just\nuse <code>PureComponent</code> or <code>memo</code> for your components that could be pure.</p>\n<h2>Some Caveats</h2>\n<p>As always, the usage depends on the case. Before using a pure component, make sure to ask yourself the following questions:</p>\n<ul>\n<li>Does my component have any non-primitive props? If so, you will need to extend the comparison function to do a deep comparison or begin using immutable objects.</li>\n<li>Does the presentation of my component depend entirely on state and/or props? Pure components assume that the component doesn't need re-rendered if those don't change, but maybe that isn't the case.</li>\n<li>Does my component have any children that <strong>may</strong> need updated, even if my component doesn't? Remember how React re-renders the entire subtree of the component? Well, that also means that if the\ncomponent doesn't re-render than none of the children do either.</li>\n</ul>\n<p>If the answer to any of these questions is \"yes\" then you may need to reconsider using pure components in this case. If not, you should be free to proceed and take back those extra render cycles. Enjoy.</p>","frontmatter":{"date":"July 11, 2020","slug":"/blog/2020-07-11","title":"Optimizing your React component lifecycle using Pure Components"}}},"pageContext":{"slug":"/blog/2020-07-11"}}}