Hey, please counter check the documentation again. To paraphrase what the documentation state, “This makes reading this.state right after calling setState() a potential pitfall. Instead, use componentDidUpdate or a setState callback (setState(updater, callback)), either of which are guaranteed to fire after the update has been applied.”
Componentdidupdate is invoked immediately when update occurs so you can compare prevstate with state and update accordingly.
The setState callback guarantee that to fire after update has been applied.