mapStateToProps returns nothing but your app's state
stored in the global store and passed to your component as props
.
mapDispatchToProps wraps your action creator in the redux's dispatch
method and pass it again as a prop
to your container. So basically the global store's state
and action creators wrapped with dispatch are all together passed as props to your component. You are passing state and the redux's dispatch method as a prop to the component.
mapDispatchToProps = dispatch => ({
dispatchAnAction: dispatch(actionCreator1)
})
Here the connected component say ComponentA
will receive the props and one of the prop will be dispatchAnAction
which is returned by mapDispatchToProps
as in the above code. You will call the dispatchAnAction
like this this.props.dispatchAnAction()
and the action returned by the actionCreator1
will be dispatched to the global redux store.
P.S If you are starting wth redux this course is highly recommended.