So I know, very basically, that redux-thunk works to return a function instead of an action in an action creator, allowing us to then dispatch something to the state (eg when a promise is resolved). What I don't understand is why, when using redux-thunk, we don't need to explicitly mapDispatchToProps in a component and dispatch that action (I was told redux-thunk is already dispatching). Can anyone explain how this works at all?
0
votes
1 Answers
1
votes
You do need mapDispatchToProps
to allow the component to initiate the action in the first place. Wether it's sync or async doesn't matter.
But with async actions, where often promises are resolved as you pointed out, the components aren't involved in handling the results. Instead you dispatch an action (typically something that ends in _SUCCESS or _RECEIVE or _SAVE or something) in the same action creator function, which the reducer sees and changes the redux state.
This in turn feeds changed props to the component via mapStateToProps
. Only then is the component involved again.