Skip to content

Instantly share code, notes, and snippets.

@Tin-Nguyen
Created April 14, 2017 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tin-Nguyen/41eb3c739d7a839eaacd204b5603f606 to your computer and use it in GitHub Desktop.
Save Tin-Nguyen/41eb3c739d7a839eaacd204b5603f606 to your computer and use it in GitHub Desktop.
// bad
componentWillMount() {
this.setState({
computedFoo: compute(this.props.foo)
});
},
componentWillReceiveProps(nextProps) {
this.setState({
computedFoo: compute(nextProps.foo)
});
},
render() {
return <div>{ this.state.computedFoo }</div>;
}
// better
render() {
var computedFoo = compute(this.props.foo);
return <div>{ computedFoo }</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment