Check out a free preview of the full State Management in Pure React, v2 course:
The "document.title Solution" Lesson is part of the full, State Management in Pure React, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Steve live codes the solution to the document.title exercise.

Get Unlimited Access Now

Transcript from the "document.title Solution" Lesson

>> All right, so our mission is to set the document title. Let's do this in the kind of like simplest possible way first. And then we'll kinda look at how we could refactor a little bit. So I could say something along the lines of document.title. I'll just use, let's say, Count is this.state.count.

[00:00:26] All right, so let's try it out [SOUND]. You see it's count 15. If I reset it, It goes up with increment. Now, if we wanna do it for all three, we don't wanna write the same function three times. What we probably want to do is figure out a way to abstract this.

[00:00:49] So, I think I alluded to it before, right? We could do something like, update, UpdateDocumentTitle. Equals this. Yep, state.count. We'll have to do the same thing we did up here, which we'll do this.updateDocumentTitle, Bind(this). Great, and now we'll just put that in all three places. Once. So this was so using the object notation, but that is totally fine, it will work either way, we don't have to do the other just to update document title, We'll flip back over.

[00:02:05] And it's changing along with the, I didn't do the count this time, it was just the row number. Because it's changing as I incremented as I decrement in both cases. All right, so that concludes kind of all of the different kinda kicking at the tires of the API of the state.

[00:02:23] You can now also put that on your resume as well, that is not, I don't know, if that's really gonna rake in the big bucks. But you never know, it's worth it. So, let's talk a little bit more just some patterns around state. And then we're gonna dive into how it differs from hooks a little bit.