flushSync

Forces React to flush pending updates synchronously inside a callback.

Since React 18 Spec ↗

Syntax

flushSync(callback)

Parameters

NameTypeRequiredDescription
callback function Yes Function whose state updates should be applied synchronously before flushSync returns.

Returns

undefined — flushSync returns nothing.

Examples

import { flushSync } from 'react-dom';

flushSync(() => {
  setCount(c => c + 1);
});
// DOM is updated here, before the next line
node.scrollIntoView();

Notes

Use it only when you must read or act on the updated DOM immediately, such as before measuring or scrolling. It opts out of batching and concurrent features, hurting performance, so reach for it rarely. Do not call it during rendering.

See also