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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Out of curiosity, was there a particular reason why you hadn't been using
mapDispatch
prior to this?Also, note that we specifically recommend that you use the "object shorthand" form of mapDispatch rather than the function form:
On the other hand, note that with our new React-Redux hooks API, there's just a useDispatch() hook that gives you access to
dispatch
.I talked about some of the differences between
connect
and the hooks API in my post Thoughts on React Hooks, Redux, and Separation of Concerns and my ReactBoston 2019 talk on Hooks, HOCs, and Tradeoffs.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 acrossuseDispatch
. 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 usinguseDispatch
is very similar to just connecting a component and calling the dispatch function, which kind of equals not usingmapDispatch
. I prefer the explicitness the HOC approach provides in tests and how easy it becomes to validate them.