JavaScript · Senior · Question 18 of 75
Why is ResizeObserver better than a window.resize handler for a component?
- ✓Correct answer: It reports size changes of a specific element for any reason
- 2It fires more often and more precisely, on every pixel of window change
- 3It lets you resize an element without recalculating layout
Explanation
An element can change size without the window changing: a sidebar opened, content loaded. ResizeObserver tracks the element itself and is called in the rendering cycle, without polling getBoundingClientRect. Useful for charts and virtualized lists.