Skip to content

Instantly share code, notes, and snippets.

@gt3
Last active March 9, 2017 17:42
Show Gist options
  • Save gt3/34487a609fe75f70ff33376e86c22aac to your computer and use it in GitHub Desktop.
Save gt3/34487a609fe75f70ff33376e86c22aac to your computer and use it in GitHub Desktop.
Temperature Calculator from React official docs
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>
}
@gt3
Copy link
Author

gt3 commented Mar 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment