If we are connecting to the action by using the dispatch there are two way:-
1. this.props.dispatch(requestEmployees());
2. const mapDispatchToProps = (dispatch) => ({
requestEmployees: () => dispatch(requestEmployees())
});
If we are doing the same with the help of bindActionCreators then our code we will be:-
function matchDispatchToProps(dispatch) {
return bindActionCreators({ editLabResult: requestEmployees}, dispatch);
}
Now my question is, which one I should use dispatch or bindActionCreators? What is the difference between them?
It's actually the same thing. The result of
Is what you've manually created:
According to the redux
bindActionCreators
documentation:Instead of using
bindActionCreators
, you can pass the object to theconnect
method, and it will do the wrapping for you: