using state to set true and false in react code example Example: toggle boolean state react this.setState(prevState => ({ check: !prevState.check }));