react update state then do something code example
Example 1: update state in react
You have to use setState() for updating state in React
{
hasBeenClicked: false,
currentTheme: 'blue',
}
setState({
hasBeenClicked: true
});
Example 2: how to update state in react
// Correct
this.setState(function(state, props) {
return {
counter: state.counter + props.increment
};
});