Skip to content

Instantly share code, notes, and snippets.

@h4091
Last active December 28, 2018 15:02
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 h4091/ee64b056bd38cd51ba460784b7be504c to your computer and use it in GitHub Desktop.
Save h4091/ee64b056bd38cd51ba460784b7be504c to your computer and use it in GitHub Desktop.
Test19
<div id="root"></id>
function BoilingVerdict(props) {
if (props.celsius >= 100) {
return <p>The water would boil.</p>
}
return <p>The water would not boil.</p>
}
class Calculator extends React.Component{
constructor(props) {
super(props);
this.state = {temperature: ''};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({temperature: event.target.value});
}
render() {
const temperature = this.state.temperature;
return (
<fieldset>
<legend>Enter temperature in Celsius:</legend>
<input value={temperature} onChange={this.handleChange} />
<BoilingVerdict celsius={temperature} />
</fieldset>
);
}
}
ReactDOM.render(
<Calculator />,
document.getElementById("root")
);
<script src="https://unpkg.com/react/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>

Test19

Learn the fundamentals of React, including simple and class components, state, props, and submitting form data.

Lifting State Up

A Pen by 你银子掉了 on CodePen.

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