how to use setstate prevstate with a function code example Example: this.setstate prevstate this.setState(prevState => ({ n: !prevState.n }))