Capítulo 72 de 116
act(callback) is a testing utility that ensures all state updates, Effects, and other queued React work triggered inside callback finish processing before assertions run — the mechanism most testing libraries (React Testing Library, etc.) already wrap around your interactions internally.
act, a test might assert on the DOM before an Effect-triggered state update has actually applied, producing a flaky or wrong assertion.act internally around render()/fireEvent()/userEvent calls — writing a raw act(() => {...}) by hand is uncommon except when testing outside those helpers or with lower-level test utilities.await act(async () => { ... }) flushes microtask-queued updates (e.g. from a resolved promise inside an event handler) as well, not just synchronous ones.act has no role in application code — it exists purely to make test assertions deterministic against React's internal scheduling.act without calling it directly — reach for it explicitly mainly when writing lower-level custom test utilities.act is exclusively a testing tool — never import or use it in production application code.act ensures has settled before assertions run.