Skip to content

Instantly share code, notes, and snippets.

@linuxenko
Created March 31, 2016 06:11
Show Gist options
  • Select an option

  • Save linuxenko/0271433314bc02ffe117be63569cf233 to your computer and use it in GitHub Desktop.

Select an option

Save linuxenko/0271433314bc02ffe117be63569cf233 to your computer and use it in GitHub Desktop.
import { connect } from 'react-redux';
import { Component } from 'react';
class SandwichShop extends Component {
componentDidMount() {
this.props.dispatch(
makeASandwichWithSecretSauce(this.props.forPerson)
);
}
componentWillReceiveProps(nextProps) {
if (nextProps.forPerson !== this.props.forPerson) {
this.props.dispatch(
makeASandwichWithSecretSauce(nextProps.forPerson)
);
}
}
render() {
return <p>{this.props.sandwiches.join('mustard')}</p>
}
}
export default connect(
state => ({
sandwiches: state.sandwiches
})
)(SandwichShop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment