mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
ballmer-peak: use composition instead of mutable state
This commit is contained in:
1 parent
5d3b12bb3b
commit
cc0e7d2a79
1 file changed
+5
-6
@@ -10,6 +10,10 @@ function computeBallmerPeak(x) {
|
||||
) / 1.6;
|
||||
}
|
||||
|
||||
function percentage(x) {
|
||||
return isNaN(x) ? 'N/A' : (100 - Math.round(pct * 100)) + '%';
|
||||
}
|
||||
|
||||
var BallmerPeakCalculator = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {bac: 0};
|
||||
@@ -18,12 +22,7 @@ var BallmerPeakCalculator = React.createClass({
|
||||
this.setState({bac: event.target.value});
|
||||
},
|
||||
render: function() {
|
||||
var pct = computeBallmerPeak(this.state.bac);
|
||||
if (isNaN(pct)) {
|
||||
pct = 'N/A';
|
||||
} else {
|
||||
pct = (100 - Math.round(pct * 100)) + '%';
|
||||
}
|
||||
var pct = percentage(computeBallmerPeak(this.state.bac));
|
||||
return (
|
||||
<div>
|
||||
<img src="./ballmer_peak.png" />
|
||||
|
||||
Reference in new issue
Block a user