write state in the class component react code example
Example 1: setstate react js
constructor(props) {
super(props);
this.state = {
isActive: true,
};
}
checkStatus = () => {
this.setState({ // use this function
'isActive' : !this.state.isActive,
});
}
Example 2: reading state react
<button onClick={() => this.setState({ count: this.state.count + 1 })}>
Click me
</button>