Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import {action1, action2} from "myActions";
import {bindActionCreators} from "redux";
const mapDispatchToProps(dispatch) => {
return {
manuallyBoundAction : (...args) => dispatch(action1(...args)),
autoBoundAction : bindActionCreators(action2, dispatch),
multipleActionsTogether : bindActionCreators({action1, action2}, dispatch)
const MyComponent = (props) => {
return (
<button onClick={props.manuallyBoundAction}>Run First Action</button>
<button onClick={props.autoBoundAction}>Run Second Action</button>
<button onClick={props.multipleActionsTogether.action1}>Run Third Action</button>
<button onClick={props.multipleActionsTogether.action2}>Run Fourth Action</button>
export default connect(null, mapDispatchToProps)(MyComponent);
// or, you can use the shorthand object argument for mapDispatch:
export default connect(null, {action1, action2})(SomeOtherComponent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment