State and how to update
have the control of your components is primordial in any web application, knowing that, we have developed a very simple way to control and update your component state.
You just need to call the setState()
method to delete, update or add a new state:
handleKeyPress(){
setState({
fooValue: 'foo'
})
}
In the example above, we are adding or updating the state of fooValue
of our component when the handleKeyPress
method is called. If the fooValue state is used in the render
method of our component, this component will call the render method again, to update the HTML tag or the value that was changed.
Now if you use this.state.fooValue
in your component, you will get the new or the updated value of foo. You can also edit more than one state in the setState
method, you just need to parse the object: value
follow by ,
in the setState
method.