Current section: Optimize Rendering 33 exercises
solution

Component Memoization

Loading solution

Transcript

00:00 This really isn't a lot of code changes, but I want you to spend time in the development tools. So let's change the code and we'll explore what things look like in the DevTools. So I'm going to get my list item, and that's coming from memo, which we're going to pull from React, and close that up here. Let's see what happens just with that change,

00:19 that one change by itself, how does that impact our performance? So I'm still on a 6x slowdown, I hit record, come over here, hit force re-render, and we stop, and holy smokes, that actually made a big impact. Before it was all red and now it's not. But you'll notice it's not totally short,

00:38 like here we're getting 21 milliseconds, our budget is 16, and so it's still not quite super awesome, but it is certainly a lot better. I think largely the reason it's not quite super awesome, is because we still have 500 elements that we're rendering here and every one of them is going to have to

00:58 compare all of the props to see, did this one change, did that one change, did that one change, that one change. So this isn't going to just magically make everything faster, it does have a cost, but it is going to definitely make this particular experience quite a bit

01:14 faster for this unnecessary re-render situation. We can of course take a look at the profiler, hit record on this, force re-render, stop recording, and look at that. Yeah, just one component re-rendered, the city chooser, all of the list items under the city chooser didn't need to re-render.

01:32 So we accomplished our task, but we're definitely not done, so let's get into the next one.