Skip to content

Instantly share code, notes, and snippets.

@mattfordham
Created May 5, 2017 20:16
Show Gist options
  • Save mattfordham/9bb8587866b955f670e6b6062ff77a52 to your computer and use it in GitHub Desktop.
Save mattfordham/9bb8587866b955f670e6b6062ff77a52 to your computer and use it in GitHub Desktop.
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