Skip to content

Instantly share code, notes, and snippets.

@markerikson
Last active September 18, 2021 09:19
Show Gist options
  • Save markerikson/f46688603e3842af0f9720dea05b1a9e to your computer and use it in GitHub Desktop.
Save markerikson/f46688603e3842af0f9720dea05b1a9e 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