React version: 17.0.2
Browser: recent versions of Chrome/Safari/Firefox
Steps To Reproduce
- Write multiple state updates in
ResizeObserver callback.
- Cause observer target to change size.
Link to code example: https://codesandbox.io/s/resizeobserver-not-batch-state-update-6rb6y
The current behavior
Each state update in ResizeObserver callback leads to an individual re-rendering of component.
In my example, calling addCounter() three times in ResizeObserver callback results in the component being re-rendered three times.
In contrast, calling addCounter() three times in button onClick event causes only a single re-rendering of component.
The expected behavior
Multiple state updates in ResizeObserver callback are batched and cause a single re-rendering of component, which helps improve performance.