Declaratively Interact with Complex Component State using the React useReducer Hook

InstructorKent C. Dodds

Share this video with your friends

Send Tweet

Having to use useState for every item in your state quickly gets cumbersome. In this lesson, we’ll learn how to refactor our component to use useReducer instead.

We'll cover:

  • Creating an initial state with useReducer
  • Making a reducer function that makes changes to the state based on incoming dispatches
Joost Galama
~ 6 years ago

Why do you use a ref to store the intervalId?

Joost Galama
~ 6 years ago

Whoops, comment belongs to previous video in list.

~ 3 years ago

Looks like the code is no longer at sandbox...

Lucas Minter
~ 3 years ago

Looks like the code is no longer at sandbox...

I got this fixed. The github changed from master branch to main branch and that messed up the codesandbox.