class component in react for setstate code example
Example 1: this setstate previous state react
state = {count: 0}
increment = () => {
this.setState(previousState => ({
count: previousState.count + 1
}))
}
Example 2: setstate react js
constructor(props) {
super(props);
this.state = {
isActive: true,
};
}
checkStatus = () => {
this.setState({ // use this function
'isActive' : !this.state.isActive,
});
}