DEV Community

Discussion on: Let's talk React - How to use a Custom Hook multiple times

Collapse
 
link2twenty profile image
Andrew Bone

Nice introductory article into custom hooks and destructing. This example would benefit from using useReducer rather than useState. I think you can learn all the same lessons (though we'd use an array rather than an object) and the end product would be more powerful while using less memory.

I did a quick example 😊

Collapse
 
ccreusat profile image
Clément Creusat

You're totally right. If a custom hook is more complex, we definitely need to re-think it with useReducer.
Here we have a state and two methods (three with your example and the reset method).. but if the custom hook has x methods better to switch to the useReducer approach.