36 lines
801 B
JavaScript
36 lines
801 B
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
|
|
class MyForm extends React.Component {
|
|
constructor(props){
|
|
super(props);
|
|
this.state ={value: ''};
|
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
this.handleChange = this.handleChange.bind(this);
|
|
}
|
|
|
|
handleChange(event){
|
|
this.setState({value: event.target.value});
|
|
}
|
|
|
|
handleSubmit(event){
|
|
console.log('Submitted: ' + this.state.value);
|
|
event.preventDefault();
|
|
}
|
|
|
|
render(){
|
|
return <form onSubmit={this.handleSubmit}>
|
|
<label>Name:
|
|
<input type="text" value={this.state.value} onChange={this.handleChange} />
|
|
</label>
|
|
<input type="submit" value="Submit" />
|
|
</form>
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(
|
|
<div>
|
|
<MyForm />
|
|
</div>,
|
|
document.querySelector('#root')); |