Last active
March 9, 2017 17:42
-
-
Save gt3/34487a609fe75f70ff33376e86c22aac to your computer and use it in GitHub Desktop.
Temperature Calculator from React official docs
This file contains 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
export const scaleNames = { c: 'Celsius', f: 'Fahrenheit' } | |
export class TemperatureInput extends React.Component { | |
constructor(props) { | |
super(props); | |
this.handleChange = this.handleChange.bind(this); | |
} | |
handleChange(e) { | |
this.props.onChange(e.target.value); | |
} | |
render() { | |
const value = this.props.value; | |
const scale = this.props.scale; | |
return ( | |
<fieldset> | |
<legend>Enter temperature in {scaleNames[scale]}:</legend> | |
<input value={value} onChange={this.handleChange} /> | |
</fieldset> | |
) | |
} | |
} | |
export function BoilingVerdict(props) { | |
if (props.celsius >= 100) return <p>The water would boil.</p> | |
return <p>The water would not boil.</p> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
React official example: https://facebook.github.io/react/docs/lifting-state-up.html