@rescui/use-resize-observer 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# ResizeObserver hook
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package is used for observing react elements.
|
|
4
|
+
It uses `ResizeObserver` and alleviates some of its bugs.
|
|
5
|
+
|
|
6
|
+
It's best used together with React refs. It can be used with raw `HTML` elements, although it's better to avoid that.
|
|
7
|
+
|
|
8
|
+
## Usage examples
|
|
9
|
+
|
|
10
|
+
### React ref example
|
|
4
11
|
|
|
5
12
|
```tsx
|
|
6
13
|
import React, { useRef } from 'react';
|
|
@@ -15,3 +22,21 @@ const MyComponent = () => {
|
|
|
15
22
|
return <div ref={ref}>To the moon!</div>;
|
|
16
23
|
};
|
|
17
24
|
```
|
|
25
|
+
|
|
26
|
+
### HTML element example
|
|
27
|
+
|
|
28
|
+
**Note:** Avoid this option when possible due to additional re-renders when using [callback refs](https://legacy.reactjs.org/docs/refs-and-the-dom.html#callback-refs) and `useState`. Use React ref instead.
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import React, { useState } from 'react';
|
|
32
|
+
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
33
|
+
|
|
34
|
+
const MyComponent = () => {
|
|
35
|
+
const [el, setEl] = useState<HTMLElement>(null);
|
|
36
|
+
useResizeObserver(el, (entry: ResizeObserverEntry) => {
|
|
37
|
+
// resize logic
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return <div ref={setEl}>To the moon!</div>;
|
|
41
|
+
};
|
|
42
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/use-resize-observer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "ResizeObserver hook",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"react": ">=16.8.0 <18"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@rescui/scripts": "^0.
|
|
24
|
+
"@rescui/scripts": "^0.2.0"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "rescui-scripts build"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "c87adfdebe07392a0aa67ce434ce465762d8fa95"
|
|
30
30
|
}
|