DEV Community

How To Use Redux With React

John Au-Yeung on December 28, 2019

Subscribe to my email list now at http://jauyeung.net/subscribe/ Follow me on Twitter at https://twitter.com/AuMayeung If you want to make a sing...
Collapse
 
garrisond profile image
Ihor Dotsenko

Use useDispatch and useSelector instead of connect.

It's a pity that you suggest to use connect in 2020 🥺

Collapse
 
dance2die profile image
Sung M. Kim • Edited

Redux hooks have ups and downs compared to connect.

connect lets you decouple your component (making it resuable) but a lot of times that abstraction might not be needed. Then you'd use useDispatch/useSelector. But hooks are really darn easy though, and more readable even though it's usable only within function components.

So the bottomline is knowing both ways would help understand trade-offs and when to use each one.

Collapse
 
aumayeung profile image
John Au-Yeung

Yea. The hooks have to be in the component. This is inherent to using hooks instead of connect.

Collapse
 
garrisond profile image
Ihor Dotsenko
Collapse
 
aumayeung profile image
John Au-Yeung

Thanks for pointing that out.

I have to update that.