Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cdoremus/4b7967c14aa73e325f58f13ca3cb3205 to your computer and use it in GitHub Desktop.
Save cdoremus/4b7967c14aa73e325f58f13ca3cb3205 to your computer and use it in GitHub Desktop.
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 (
<div>
<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>
</div>
)
}
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