DEV Community

Discussion on: Why I'll definitely use mapDispatchToProps in Redux

Collapse
keraito profile image
Chak Shun Yu Author

Not in particular. I never came across the docs for mapDispatch, so I didn't know of its existence. I also didn't see it before in projects that I either worked on or contributed to, so that didn't help either.

I consciously decided to illustrate the function form, because I feel like it better describes what mapDispatch is and what its purpose is. But I definitely like the object shorthand!

While looking into mapDispatch after the first time I learned about it, I also came across useDispatch. I haven't read the links that you mentioned yet (but definitely will do!), but I personally rather stick with the HOC construction. It keeps class and function components interchangeable (at my job we use class components) and I feel like using useDispatch is very similar to just connecting a component and calling the dispatch function, which kind of equals not using mapDispatch. I prefer the explicitness the HOC approach provides in tests and how easy it becomes to validate them.