Mark As Completed Discussion

How can you update the state of a component?

JAVASCRIPT
1// State of a component can be updated using this.setState().
2class MyComponent extends React.Component {
3	constructor() {
4		super();
5		this.state = {
6		name: 'Maxx',
7		id: '101'
8		}
9	}
10	render()
11	{
12	setTimeout(()=>{this.setState({name:'Jaeha', id:'222'})},2000)
13	return (<div>
14				<h1>Hello {this.state.name}</h1>
15				<h2>Your Id is {this.state.id}</h2>
16		</div>);
17	}
18}
19
20ReactDOM.render(
21	<MyComponent/>, document.getElementById('content')
22);