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