class NameForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) { this.setState({value: event.target.value}); }
handleSubmit(event) {
alert('A name was 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>
);
}
}
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: 'Bound data...'
}
this.updateState = this.updateState.bind(this);
};
updateState(e) {
this.setState({data: e.target.value});
}
render() {
return (
<>
<input type="text" value = {this.state.data} onChange = {this.updateState} />
<h4>{this.state.data}</h4>
</>
);
}
}
ReactDOM.render(
<App />, document.getElementById('mountNode') );
import React from "react";
function App() {
function handleChange(event) {
console.log(event.target.value);
}
return (
<input
type="text"
name="firstName"
onChange={handleChange}
/>
);
}
export default App;