1import React, { Component } from 'react';
2
3import './App.css';
4import Header from './Header';
5
6class App extends Component {
7
8 constructor(props) {
9 super(props);
10 this.state = {name: "Michael"}
11
12 }
13 changeTitle = (e) =>{
14 this.setState({name: e.target.value});
15 }
16
17 render() {
18 return (
19 <div className="App">
20 <Header title={this.state.name}/>
21 <p className="App-intro">
22 Type here to change name.
23 <input type="text" onChange={this.changeTitle}/>
24 </p>
25 </div>
26 );
27 }
28}
29
30export default App;
1In React, onChange is used to handle user input in real-time.
2
3If you want to build a form in React, you need to use this event to track
4the value of input elements.