Current section: Optimize Rendering 33 exercises
Problem

Component Memoization

Loading exercise

Transcript

00:00 Let's optimize this component further. If I slow us down to 6x and I start recording, then I click force re-render, and then stop. We'll just assume like the parent re-rendered, something happened. Then we get a bunch of red right here, and that's not great. And the reason that's happening is because we end up rendering

00:17 a ton of components right down here. Yeah, there we go, list item. You're going to get a bunch of those. If we open up the profiler, so now that we've established, oh, there's a problem, we open up the profiler now, and I click on force re-render, then we'll be able to see what React sees as re-rendering.

00:35 And looking at the flame graph, you'll see this, but it doesn't actually show all of them, which is why I typically look at the ranked view. And yeah, holy smokes, there's a lot. So yeah, this is not great. Even though the individual components are not taking a long time,

00:52 it's just that there's so many of them. We want to eventually render all of the city results. Right now we're just slicing for the first 500, but we've got users who want to scroll forever, and so we want to render all of them. And yeah, this will not work if we do things that way.

01:10 So what we're going to do is optimize our list item component using memo. So let's give that a try and see how that impacts the performance of what happens when we click force re-render.