Using Hooks to Replace Redux

Make your life easier with lifecycle hooks and state management in functional components

Photo by Nathan Dumlao on Unsplash
Photo by Nghia Le on Unsplash

Accepts a reducer of type (state, action) => newState, and returns the current state paired with a dispatch method. (If you’re familiar with Redux, you already know how this works.)

I wonder — maybe Redux is mentioned for a reason, and I could use this to make centralized state management just like Redux. And why not use useState? It does almost the same thing but in a different way. React documentation states that when called useState returns a stateful value and a function to update it.

Context provides a way to pass data through the component tree without having to pass props down manually at every level.

It’s kind of a one-way, shared, centralized state that components react to when changed. Now have useContext hook. It seems we have chosen the best tools for the work — let’s make them work together.

Better Programming

Advice for programmers.

Rogerio Amorim

Written by

Better Programming

Advice for programmers.