Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Tamal/91a1df45c3bd0037a465fe5f6106ec2d to your computer and use it in GitHub Desktop.
Save Tamal/91a1df45c3bd0037a465fe5f6106ec2d 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