Created
May 5, 2017 20:16
-
-
Save mattfordham/9bb8587866b955f670e6b6062ff77a52 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 React, { Component, PropTypes } from 'react'; | |
import { connect } from 'react-redux'; | |
import peopleActions from './peopleActions'; | |
export class MyComponent extends Component { | |
componentWillMount() { | |
this.props.fetchPeople(); | |
} | |
render() { | |
const { people } = this.props; | |
return ( | |
<div> | |
{people} | |
</div> | |
); | |
} | |
} | |
MyComponent.propTypes = { | |
people: PropTypes.array, | |
fetchPeople: PropTypes.func | |
}; | |
function mapStateToProps(state) { | |
return { | |
people: state.people | |
}; | |
} | |
function mapDispatchToProps(dispatch) { | |
return { | |
fetchPeople() { | |
dispatch(peopleActions.fetch()); | |
} | |
}; | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(MyComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment