useResizeObserver doesn't work with changing refs
sandrosc opened this issue · comments
Sandro Scheiwiller commented
Changing refs, like in the following example, leads to both DOM nodes being observed, since the first node is never unobserved.
const DOMRect = useResizeObserver(first ? ref1 : ref2);
Example: https://codesandbox.io/s/black-dew-36k642?file=/src/App.js
- First box is being observed, second box not.
- Click button.
- Expected: Second box should be observed, first box not. Actual behaviour: Both boxes are observed.