Current section: useState 16 exercises
lesson

Introduction to useState

Transcript

00:00 The first hook we're going to be implementing ourselves is useState. So you can't use useReducer under the hood or no useRef under the hood or anything like that. You're going to be implementing useState from scratch without any other React components or hooks or anything like that.

00:17 So this means you need to handle that initial state value that gets passed to us. We also need to handle updating the state. So when setCount is called, we need to update the state. But then we're also going to have to deal with re-rendering, which is going to be an interesting challenge in itself.

00:33 And we need to preserve the state so that as we re-render, we're accessing the same value of state. So each one of the exercises steps in this exercise is going to be pretty short, pretty quick. But it's very intentional, and I think that you're going to have a good time with it. So let's get started.