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/a445604c14daa09ba92dd69c040bc0ea to your computer and use it in GitHub Desktop.
Save h4091/a445604c14daa09ba92dd69c040bc0ea to your computer and use it in GitHub Desktop.
Test18
<div id="root"></div>
class Reservation extends React.Component {
constructor(props) {
super(props);
this.state = {
isGoing: true,
numberOfGuests: 2
};
this.handleInputChange = this.handleInputChange.bind(this);
}
handleInputChange(event) {
const target = event.target;
const name = target.name;
const value = target.type === "checkbox" ? target.checked : target.value;
this.setState({
[name]: value
});
}
render() {
return (
<form>
<label>
Is going:
<input name="isGoing" type="checkbox" checked={this.state.isGoing} onChange={this.handleInputChange} />
</label>
<br/>
<label>
Number of guests:
<input name="numberOfGuests" type="number" value={this.state.numberOfGuests} onChange={this.handleInputChange} />
</label>
</form>
);
}
}
ReactDOM.render(
<Reservation />,
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>

Test18

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

Multiple Inputs Example

A Pen by 你银子掉了 on CodePen.

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