Answer the question
In order to leave comments, you need to log in
Why do we need bindActionCreators?
function mapDispatchToProps(dispatch) {
return {
getProducts: () => dispatch(getProducts()),
};
}
{getProducts}
Answer the question
In order to leave comments, you need to log in
bindActionCreators takes an object with AC as input , or a function and returns an object with AC wrapped in a call to dispatch or, in the case of a function, a function wrapped in dispatch .
If you pass an object to connect as the second argument:
const mapDispatchToProps = {
getProducts,
};
const mapDispatchToProps = (dispatch, ownProps) => ({
getProducts: () => dispatch(getProducts()),
});
cosnt mapDispatchToProps = dispatch => bindActionCreators(
{
getProducts,
},
dispatch,
);
const mapDispatchToProps = (dispatch, ownProps) => ({
...bindActionCreators(
{
...productsActions,
...usersActions,
...ordersActions,
},
dispatch,
),
() => getSomeOther(ownProps.someProp),
notNeedsToWrapInDispatch,
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question