Reputation: 2215
I learn React Redux and reading here about using mapDispatchToProps
and bindActionCreators
It works fine the bindActionCreators
when using it alone like so:
export default connect(null, (dispatch) =>
bindActionCreators(actionCreators, dispatch)
)(FormContainer);
But I have more actions and tried this:
function mapDispatchToProps(dispatch) {
return {
bindActionCreators(actionCreators, dispatch),
clearPosts: () => dispatch(clearPosts()),
}
}
And that gives error like so:
. How can I combine them I read the docs and there's nothing as I can see about this please advice
Upvotes: 0
Views: 33
Reputation: 44326
It is recommended to use the "map object" notation nowadays if you really want to use connect
.
const mapDispatchToProps = {
...actionCreators,
clearPosts
}
But also, the recommendation is to use redux hooks instead of connect if you can use function components, as they are generally easier to use.
(If you were following a tutorial that was showing you connect
, it might be outdated, please see the official redux tutorials instead)
Upvotes: 2
Reputation: 820
try below code
function mapDispatchToProps(dispatch) {
return {
todoActions: bindActionCreators(actionCreators, dispatch),
clearPosts: () => dispatch(clearPosts()),
}
}
Upvotes: 1