How to Refactor To the useState Hook

Brett Cassette
InstructorBrett Cassette
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

In this lesson we'll take an existing class component and refactor it to use the useState React Hook. We'll see what changes between class and function components and also how to use the useState method.

Luca Lischetti
Luca Lischetti
~ 5 years ago

Why using let instead of const with useState? It shouldn't be more correct having const in order to show that we shouldn't touch those variables?

Brett Cassette
Brett Cassetteinstructor
~ 5 years ago

Good point, Luca, const will be more technically correct and will communicate your intentions better to fellow programmers, since state will not change during each render. Even with the useRef hook which communicates imperative, mutable code, usually the common usage is still const, although sometimes you'll see a let. Thanks for pointing this out!

Markdown supported.
Become a member to join the discussionEnroll Today