Update act() usage to be async in examples
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
actwithawaitand 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.
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! 🙌