Created
February 9, 2018 08:06
-
-
Save marsbomber/1b6efd125f31e1ff2632985e0aaf439e 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
// utils/partial.js | |
export const partial = (func, ...args) => func.bind(null, ...args); | |
// actions/maths.js | |
export const addNumberOneAndNumberTwo = (first, second) => { | |
return { | |
type: 'SOMETHING THE REDUCER CAN CATCH', | |
first, | |
second, | |
}; | |
}; | |
// containers/entry.js | |
import Entry from '../components/entry'; | |
// other redux stuff | |
import { addNumberOneAndNumberTwo } from '../actions/maths'; | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
addNumberOneAndNumberTwo: (first, second) => { | |
// you can see here I do NOTHING, just push the args I receive into the | |
// actual action creator func call | |
dispatch(addNumberOneAndNumberTwo(first, second)); | |
} | |
}; | |
}; | |
connect(mapStateToProps, mapDispatchToProps)(Entry); | |
// components/entry.js | |
import React, { Component } from 'react'; | |
import NextLevel from './next_level'; | |
class Entry extends Component { | |
render() { | |
return ( | |
<div> | |
<NextLevel | |
clickHandler={partial(this.props.addNumberOneAndNumberTwo, 1)} | |
/> | |
</div> | |
); | |
} | |
} | |
export default Entry; | |
// components/next_level.js | |
import React, { Component } from 'react'; | |
class NextLevel extends Component { | |
fireIt() { | |
this.props.clickHandler(2); | |
} | |
render() { | |
return ( | |
<div> | |
<button | |
onClick={this.fireIt} | |
> | |
Click me | |
</button> | |
</div> | |
); | |
} | |
} | |
export default NextLevel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 39 and 52: where do you normally get the parameters from? What if values 1 and 2 are already in the store?
Right now, I have those values passed in from mapStateToProps. Do you use local state for these?