act()
A React test helper that runs a piece of code and then finishes all resulting renders and effects before you check the result.
In more detail
Wrapping root.render or a simulated click in act makes the page reflect the update, so the next line can read it. In React 19 act is imported from react, and the async form await act(async () => ...) also waits for promises.
Example
await act(async () => { root.render(<App />); });Related terms
- createRoot — The React DOM function that turns a page element into a React root, whose render method then displays a component inside it.
- useEffect — The React hook for running side work, such as adding listeners or changing document.body, after a component renders.
Taught in
- Keys In Depth: Identity Preservation And Identity Resetting — React 19 & Modern Component Architecture
- Diffing Algorithm: Element Type Shifts And Subtree Tear Down — React 19 & Modern Component Architecture
- SyntheticEvent System: Event Delegation in Modern React — React 19 & Modern Component Architecture
- useEffect Lifecycle: Mount, Dependencies, And Cleanup Phases — React 19 & Modern Component Architecture
- Avoiding Effect Antipatterns: Derived State And Events — React 19 & Modern Component Architecture
- useLayoutEffect vs useEffect: Painting And Synchronous Reads — React 19 & Modern Component Architecture
- useRef Mechanics: DOM References And Mutable Persistent State — React 19 & Modern Component Architecture
- useImperativeHandle: Controlled Ref Forwarding Boundaries — React 19 & Modern Component Architecture
- Lifting State Up: Colocation, Ownership, And Data Flow — React 19 & Modern Component Architecture
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture