You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Nowadays browsers support element resize handling natively using [ResizeObservers](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver). The library uses these observers to help you handle element resizes in React.
7
+
Modern browsers now have native support for detecting element size changes through [ResizeObservers](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver). This library utilizes ResizeObservers to facilitate managing element size changes in React applications.
🦄 Produces <ahref="https://npmtrends.com/react-resize-detector"target="__blank">100 million downloads annually</a>
18
16
19
17
No `window.resize` listeners! No timeouts! No 👑 viruses! :)
20
18
21
-
<i>TypeScript-lovers notice: starting from v6.0.0 you may safely remove `@types/react-resize-detector` from you deps list.</i>
22
-
23
-
## Do you really need this library?
19
+
## Is it necessary for you to use this library?
24
20
25
-
Container queries now work in [all major browsers](https://caniuse.com/css-container-queries). It's very likely you can resolve your problem using [pure CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries).
21
+
Container queries now work in [all major browsers](https://caniuse.com/css-container-queries). It's very likely you can solve your task using [pure CSS](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries).
<details><summary>With custom ref. _not recommended, may have some unexpected behaviour if you dynamically mount/unmount the observed element_</summary>
96
+
_It's not advised to use this approach, as dynamically mounting and unmounting the observed element could lead to unexpected behavior._
<p>The rectangle changes color based on its width</p>
224
-
<AdaptiveWithDetector />
225
-
</div>
226
-
);
227
-
};
228
-
229
-
exportdefaultApp;
230
-
```
231
-
232
-
</details>
233
-
234
-
<br/>
235
-
236
-
We still support [other ways](https://github.com/maslianok/react-resize-detector/tree/v4.2.1#examples) to work with this library, but in the future consider using the ones described above. Please let me know if the examples above don't fit your needs.
237
-
238
-
## Refs
239
-
240
-
_The below explanation doesn't apply to `useResizeDetector`_
241
-
242
-
The library is trying to be smart and does not add any extra DOM elements to not break your layouts. That's why we use [`findDOMNode`](https://react.dev/reference/react-dom/findDOMNode) method to find and attach listeners to the existing DOM elements. Unfortunately, this method has been deprecated and throws a warning in StrictMode.
243
-
244
-
For those who want to avoid this warning, we are introducing an additional property - `targetRef`. You have to set this prop as a `ref` of your target DOM element and the library will use this reference instead of searching the DOM element with help of `findDOMNode`
0 commit comments