Yes, the behavior is similar.
React is batching the updates calls.
When Writing:
const handleClick = () => setCount(count + 1)
handleClick()
handleClick()
handleClick()
the count
in state will be 1
When Writing:
const handleClick = () =>
setCount(prevCount => {
return prevCount + 1;
});
handleClick()
handleClick()
handleClick()
the count
in state will be 3
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…