Skip to content

Instantly share code, notes, and snippets.

@geetotes
Created March 15, 2017 20:59
Show Gist options
  • Save geetotes/c63e9f00f02fd42080561b07803b587b to your computer and use it in GitHub Desktop.
Save geetotes/c63e9f00f02fd42080561b07803b587b to your computer and use it in GitHub Desktop.
class NeatoComponent extends React.Component {
constructor() {
super();
this.state = {
foo: this.props.foo,
bar: this.props.bar
};
}
componentWillReceiveProps(nextProps) {
if (this.props !== nextProps) { // This is crappy comparison just for the purposes of this example
this.setState({
foo: nextProps.foo,
bar: nextProps.bar
});
}
}
render() {
return (<p> Foo bar: {this.state.foo} {this.state.bar}</p>);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment