Home
← All questions

Automatic batching in React 18

MediumPremiumReact

Asked at Meta · Microsoft

React interview practice: Explain state batching across event handlers, promises, and native events.

Answer

Batching groups multiple setState calls into a single re-render for performance.

  • React 17: batched only inside React event handlers.
  • React 18: automatic batching everywhere — promises, setTimeout, native event listeners, fetch callbacks.

Opt out with flushSync when you need the DOM updated immediately (e.g. measuring layout after state change).

Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium