how to access prevstate in react in setstate code example Example: this.setstate prevstate this.setState(prevState => ({ n: !prevState.n }))