React · Senior · Question 30 of 75

When is flushSync justified?

Explanation

Example: you added a message and want to scroll to it immediately - without flushSync, the new DOM node doesn't exist yet. It's also needed when integrating with third-party code like onbeforeprint. It's an expensive operation that breaks batching and concurrent optimizations - use it sparingly.

Further reading

Problem with a question

React · Senior · question 30

Test yourself

Take the React · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz