The state object is internal to a component. It holds data which can change over time. So far, we’ve used ReactJS as a static rendering engine. Now, we’re going to add state to make React components more dynamic.
The key difference between props and state is that state is internal and controlled by the component itself while props are external and controlled by whatever renders the component. Let’s see it in practice:
this.state
To access a component’s state use this.state just like how we use this.props.
this.setState
To update a component’s state, call this.setState with an object map of keys to updated values. Keys that are not provided are not affected.
123
this.setState({name:"Sokleap"})
When a component’s state changes, render is called with the new state and the UI is updated to the new output. This is the heart of React.