Created
April 14, 2017 00:59
-
-
Save Tin-Nguyen/41eb3c739d7a839eaacd204b5603f606 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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