Skip to content

It may allow beginners to taste the sweetness of not following the rules #8230

@guda-art

Description

@guda-art

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions