1class NameForm extends React.Component {
2 constructor(props) {
3 super(props);
4 this.handleSubmit = this.handleSubmit.bind(this);
5 this.input = React.createRef();
6 }
7
8 handleSubmit(event) {
9 alert('A name was submitted: ' + this.input.current.value);
10 event.preventDefault();
11 }
12
13 render() {
14 return (
15 <form onSubmit={this.handleSubmit}>
16 <label>
17 Name:
18 <input type="text" ref={this.input} />
19 </label>
20 <input type="submit" value="Submit" />
21 </form>
22 );
23 }
24}