Skip to content

Commit 824e186

Browse files
committed
mostly documentation tweaks
1 parent 022e4b5 commit 824e186

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ src
33
yarn.lock
44
yarn-error.log
55
.DS_Store
6+
.babelrc
67
rollup.config.js
78
karma.conf.js
89
.editorconfig
10+
browserslist
911
.cache
1012
.travis.yml
1113
tests

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ addons:
88
chrome: stable
99
firefox: latest
1010
script:
11+
- yarn build
1112
- yarn test:chrome:headless
1213
- yarn test:firefox:headless
1314
deploy:

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ const App = () => {
3737
};
3838
```
3939

40-
## Passing in your own `ref`
40+
## Passing in Your Own `ref`
4141

42-
You can pass in your own ref to measure, use now.
43-
This can be useful if you already have a ref from somewhere you want to measure.
42+
You can pass in your own ref instead of using the one provided.
43+
This can be useful if you already have a ref you want to measure.
4444

4545
```js
46-
const { ref, width, height } = useResizeObserver({
47-
defaultWidth: 100,
48-
defaultHeight: 50
49-
});
46+
const ref = useRef(null);
47+
const { width, height } = useResizeObserver({ ref });
5048
```
5149

5250
You can even reuse the same hook instance to measure different elements:
@@ -55,16 +53,21 @@ You can even reuse the same hook instance to measure different elements:
5553

5654
## Throttle / Debounce
5755

58-
You might want values less frequently than actually reported.
56+
You might want to receive values less frequently than changes actually occur.
5957

60-
While this hook does not come its own implementation of throttling / debouncing
61-
the reported values (Issue #19), you can use hook composition to achieve it:
58+
While this hook does not come with its own implementation of throttling / debouncing,
59+
you can use hook composition instead to achieve the same results:
6260

6361
[CodeSandbox Demo](https://codesandbox.io/s/use-resize-observer-throttle-and-debounce-8uvsg)
6462

65-
## SSR, Default Size
63+
## Defaults (SSR)
6664

67-
You can set the default size, which is useful for SSR.
65+
On initial mount the ResizeObserver will take a little time to report on the
66+
actual size.
67+
68+
Until then the hook receives the first measurement, it returns with "1x1" by default.
69+
70+
You can override this behaviour, which could be useful for SSR as well.
6871

6972
```js
7073
const { ref, width, height } = useResizeObserver({
@@ -76,10 +79,10 @@ const { ref, width, height } = useResizeObserver({
7679
Here "width" and "height" will be 100 and 50 respectively, until the
7780
ResizeObserver kicks in and reports the actual size.
7881

79-
## Without Default Measurements
82+
## No Defaults
8083

8184
If you only want real measurements (only values from the ResizeObserver without
82-
defaults), then you can use the following:
85+
any default values), then you can use the following:
8386

8487
```js
8588
const { ref, width, height } = useResizeObserver({
@@ -102,18 +105,16 @@ container/element queries:
102105

103106
By default the library provides transpiled ES5 modules in CJS / ESM module formats.
104107

105-
Polyfilling is recommended to be done in the host app, and not in the library, as
106-
that gives users more control over what exact polyfills they might want to use.
108+
Polyfilling is recommended to be done in the host app, and not within imported
109+
libraries, as that way consumers have control over the exact polyfills being used.
107110

108-
However, there's a polyfilled CJS module (without affecting globals) that can be
109-
used for convenience:
111+
That said, there's a [polyfilled](https://github.com/que-etc/resize-observer-polyfill)
112+
CJS module that can be used for convenience (Not affecting globals):
110113

111114
```js
112115
import useResizeObserver from "use-resize-observer/polyfilled";
113116
```
114117

115-
[Bundled ResizeObserver implementation](<[ResizeObserver](https://github.com/que-etc/resize-observer-polyfill)>)
116-
117118
## Related
118119

119120
- [@zeecoder/container-query](https://github.com/ZeeCoder/container-query)

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"test": "run-s build karma:run",
1717
"test:build": "parcel build tests/index.js --out-dir tests/dist",
1818
"test:watch": "parcel watch tests/index.js --out-dir tests/dist",
19-
"test:chrome": "KARMA_BROWSERS=Chrome yarn test",
20-
"test:chrome:headless": "KARMA_BROWSERS=ChromeHeadless yarn test",
21-
"test:firefox": "KARMA_BROWSERS=Firefox yarn test",
22-
"test:firefox:headless": "KARMA_BROWSERS=FirefoxHeadless yarn test",
19+
"test:chrome": "KARMA_BROWSERS=Chrome yarn karma:run",
20+
"test:chrome:headless": "KARMA_BROWSERS=ChromeHeadless yarn karma:run",
21+
"test:firefox": "KARMA_BROWSERS=Firefox yarn karma:run",
22+
"test:firefox:headless": "KARMA_BROWSERS=FirefoxHeadless yarn karma:run",
2323
"karma:run": "karma start --singleRun",
2424
"karma:watch": "karma start",
2525
"prepublish": "yarn src:build"

0 commit comments

Comments
 (0)