If you're not familiar with Redux or hooks feel free to check out my other articles explaining the topics and then come back! When I was first lear...
For further actions, you may consider blocking this person and/or reporting abuse
Glad to know that our React-Redux hooks API is working well for you!
Out of curiosity, was there anything specific about
connect
that you felt hard to work with?Note that the
mapDispatch
declaration can be shortened using the "object shorthand" form:Thank you for all you do for Redux! My biggest struggle with using connect was setting up the mapDispatchToProps function. I'm not sure why maybe I was just so overwhelmed with all the other moving pieces of Redux that it was the straw that broke the camel's back. With hooks, it felt a bit more natural and easy to understand for me. I want this state so just use the hook to grab a specific piece and then I want to dispatch an action so just call dispatch with a specific action. Fewer steps made it a bit easier for me to work with since it was broken down into more manageable pieces.
Yeah, I get what you're saying. It's just interesting to see how
connect
is sometimes described as being a lot harder to understand.mapState
anduseSelector
are basically equivalent.mapDispatch
is admittedly doing a couple more steps thanuseDispatch
, but ultimately the behavior is the same (and really code like() => dispatch(increaseVote(anime.id)
is actually doing some work thatmapDispatch
did for you.)FWIW, I'm working on a major rewrite of the Redux core docs, and my next step is to add a new tutorial page that teaches Redux Toolkit and the React-Redux hooks as the default way to use Redux. It'll be interesting to see how that turns out.
I think because 'connect' is actually where the magic happen. We do not see any code but our components gets store and functions from redux. I think also from the javascript point of view it's not common and easy to read somethings like function(function, function)(function)
Can't wait to use the toolkit in my next project!
Redux toolkit is awesome (love createSlice). It should be the way to go, to show people that redux in 2020, is easy. In a production project, I rewrite every redux part with it. Huge productivity improvment!
Yep, I'm literally working on a tutorial right now that teaches RTK as the default approach :)
Agreed that the code could be more brief, but it also makes the component harder to test in isolation (ie, without a complete store)
Nice comparison in pieces
I didn't know that we could use those kinda hooks 😮... It's really easier than use MDP and MSP .. Thank you!
Good
Do you any post to use Duck pattern, actually the better way to use it?
Awesome!
Thanks for sharing @jennifer !