-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Open
Labels
@guda-art
Description
Summary
https://react.dev/learn/queueing-a-series-of-state-updates
The first challenge in this chapter can still work normally even if it is written like this, because it relies on click behavior
async function handleClick() { setPending(pending + 1); await delay(3000); setPending(pending=>pending - 1); setCompleted(completed=>completed + 1); }
However, if it is changed to this, it will not work. At this point, we must change setPending(pending + 1) to setPending(pending => pending + 1)
async function handleClick() { setTimeout(()=> {setPending(pending + 1);}, 1000) await delay(3000); setPending(pending=>pending - 1); setCompleted(completed=>completed + 1); }
Page
https://react.dev/learn/queueing-a-series-of-state-updates
Details
Perhaps some annotations could be added