Forked from markerikson/reduxActionBindingExample.js
Created
October 4, 2017 19:04
-
-
Save javidjamae/eb52a3651f13a31952cf636f050d014b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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