Current section: Element Optimization 33 exercises
Problem

Memoize Components

Loading exercise

Transcript

00:00 So memoizing components is actually so common that React has a built-in mechanism for this. So rather than having a use memo here, we want to just render the footer directly, that JSX element directly inline into that main footer prop. But we want to also make sure that the footer

00:19 doesn't re-render unnecessarily when the app count is changed. So we're not going to be using use memo, instead we're going to be using memo from React. And what memo will do is effectively what we were doing with use memo, where it's going to take all of the props and treat those as dependencies. And if those dependencies don't change,

00:38 then our React element doesn't re-render. So that's what we're going to be doing in this exercise. We'll be using memo, not use memo, just memo from React around our footer component so that we avoid the re-render. So when you're all finished, we should not get a re-render

00:56 when incrementing the app count or the main count, but we will get a re-render when we change the color and the footer name. So give that a whirl.