@rescui/use-resize-observer 0.1.2 → 0.1.4

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.
Files changed (2) hide show
  1. package/README.md +26 -1
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # ResizeObserver hook
2
2
 
3
- ## Usage
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.2",
3
+ "version": "0.1.4",
4
4
  "description": "ResizeObserver hook",
5
5
  "license": "Apache-2.0",
6
6
  "author": "JetBrains",
@@ -18,13 +18,13 @@
18
18
  "core-js": "^3.9.1"
19
19
  },
20
20
  "peerDependencies": {
21
- "react": ">=16.8.0 <18"
21
+ "react": ">=16.8.0 <19"
22
22
  },
23
23
  "devDependencies": {
24
- "@rescui/scripts": "^0.1.7"
24
+ "@rescui/scripts": "^0.2.0"
25
25
  },
26
26
  "scripts": {
27
27
  "build": "rescui-scripts build"
28
28
  },
29
- "gitHead": "5b91fbea7e31d106ca19925f66908b080884a3b5"
29
+ "gitHead": "3fb96470654a814a47b84a55571b1454c69da15c"
30
30
  }