react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

Update act() usage to be async in examples

Open valgaze opened this issue 1 month ago • 1 comments

This 🐣 PR updates the second example on react.dev/reference/react/act to use an async callback with act() + fix an alignment issue with another sample

Although the example currently uses a synchronous callback, the documentation below it explicitly recommends always using the async form:

“We recommend using act with await and an async function. Although the sync version works in many cases, it doesn’t work in all cases… We will deprecate and remove the sync version in the future.”

Updating the example to use an async callback makes it consistent with:

  • The guidance above
  • Other examples on the page
  • The future direction of the API (nobody should do a double-take when the 1st example uses a sync callback)

This change does not alter the behavior of the example, but aligns it with the recommended best practice and helps avoid confusion for readers.

valgaze avatar Nov 14 '25 03:11 valgaze

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

github-actions[bot] avatar Nov 14 '25 03:11 github-actions[bot]