The state update is asynchronous so if you are using Hooks you can use useEffect
to be notified after an update.
Here is an example:
https://codesandbox.io/s/wxy342m6l
If you are using setState of a React component, you can use the callback
this.setState((state) => ({count: !state.count}), () => console.log('Updated', this.state.count));
Remember to use the callback to update state if you need a state value.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…