Current section: Optimize Rendering 33 exercises
solution

Primitives

Transcript

00:00 Not a ton of changes happening here. Conceptually, what's happening is, well, first of all, let's get rid of this custom comparator. We are not going to need this when we're done. What we're going to do is take this computation right here. We're going to move it right up here to our list item. And we're going to compute the isSelected

00:19 and isHighlighted right up here. We were actually already computing that below in our custom comparator. So we're not computing this any more than we were before. We're just computing it in a different place. And so here, we're going to get our selected city. The ID equal our city. The highlighted index is whether that's equal to our index.

00:37 And now, instead of a selected city, we can call this isSelected. And we'll call this isHighlighted. And with that, we can then come here and say

00:52 isSelected and isHighlighted. And we swap these out for isSelected and isHighlighted. Boom. And then that's it. Yeah, we're done. So let's just double check that this actually worked

01:08 and didn't regress our performance. So we're at a 6x slowdown. We'll record it, test that out. And yep, that's looking awesome. And then we can come over here to our profiler. And we'll record that. Make sure that the right number of components are re-rendering as a result of this change.

01:27 And they totally are. We are doing super awesome. You should feel super great, because we drastically simplified our code without negatively impacting performance. This is a PR merged. Good job.