Skip to content

Commit 9066aa5

Browse files
committed
[18] Add docs for flushSync (#4474)
* [18] Add flushSync to ReactDOM docs * Seb feedback * More Seb feedback
1 parent 7a2f6aa commit 9066aa5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

content/docs/reference-react-dom.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The `react-dom` package also provides modules specific to client and server apps
2626

2727
The `react-dom` package exports these methods:
2828
- [`createPortal()`](#createportal)
29-
29+
- [`flushSync()`](#flushsync)
3030

3131
These `react-dom` methods are also exported, but are considered legacy:
3232
- [`render()`](#render)
@@ -55,6 +55,25 @@ createPortal(child, container)
5555
```
5656

5757
Creates a portal. Portals provide a way to [render children into a DOM node that exists outside the hierarchy of the DOM component](/docs/portals.html).
58+
59+
### `flushSync()` {#flushsync}
60+
61+
```javascript
62+
flushSync(callback)
63+
```
64+
65+
Force React to flush any updates inside the provided callback synchronously. This method is useful for being able to read the result of those updates immediately.
66+
67+
> Note:
68+
>
69+
> `flushSync` can have a significant impact on performance. Use sparingly.
70+
>
71+
> `flushSync` may force pending Suspense boundaries to show their `fallback` state.
72+
>
73+
> `flushSync` may also run pending effects and synchronously apply any updates they contain before returning.
74+
>
75+
> `flushSync` may also flush updates outside the callback when necessary to flush the updates inside the callback. For example, if there are pending updates from a click, React may flush those before flushing the updates inside the callback.
76+
5877
## Legacy Reference
5978
### `render()` {#render}
6079
```javascript

0 commit comments

Comments
 (0)