2023-02-26 01:02
This commit is contained in:
36
hello_world/src/index.js
Normal file
36
hello_world/src/index.js
Normal file
@@ -0,0 +1,36 @@
|
||||
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'));
|
||||
Reference in New Issue
Block a user