@uniflowed/hooks 0.1.0 → 0.3.0
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/dom.js +18 -4
- package/package.json +3 -3
package/dom.js
CHANGED
|
@@ -42,8 +42,17 @@ import type { ScrollOffset, Size } from "./browser.js";
|
|
|
42
42
|
import { browserWindow } from "./browser.js";
|
|
43
43
|
import { useIsomorphicLayoutEffect, useStableCallback } from "./lifecycle.js";
|
|
44
44
|
|
|
45
|
-
/**
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* A ref object these hooks read: what `useRef` and `useElementRef` return.
|
|
47
|
+
*
|
|
48
|
+
* `readonly`, because the hooks only ever read `current`, and because that is
|
|
49
|
+
* what lets a caller pass the ref they already have. A ref is a mutable box,
|
|
50
|
+
* so a writable `{ current: HTMLElement | null }` is invariant, and
|
|
51
|
+
* `useRef<HTMLDivElement | null>(null)` did not fit it: every
|
|
52
|
+
* `useHover(ref)` on a `div` ref was a type error at the call. Read-only, it is
|
|
53
|
+
* covariant, and a ref to any element a hook accepts is accepted.
|
|
54
|
+
*/
|
|
55
|
+
export type Ref<T> = { readonly current: T | null };
|
|
47
56
|
|
|
48
57
|
/**
|
|
49
58
|
* What a listener can be attached to.
|
|
@@ -383,8 +392,13 @@ export hook useScroll(ref: Ref<HTMLElement>): ScrollOffset {
|
|
|
383
392
|
return offset;
|
|
384
393
|
}
|
|
385
394
|
|
|
386
|
-
/**
|
|
387
|
-
|
|
395
|
+
/**
|
|
396
|
+
* A ref for one of the hooks above, typed for the element you will attach it to.
|
|
397
|
+
*
|
|
398
|
+
* Writable, unlike [`Ref`], because React writes it: it goes to an element's
|
|
399
|
+
* `ref` prop as well as to a hook.
|
|
400
|
+
*/
|
|
401
|
+
export hook useElementRef<T extends HTMLElement>(): { current: T | null } {
|
|
388
402
|
return useRef<T | null>(null);
|
|
389
403
|
}
|
|
390
404
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniflowed/hooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The React hooks an application writes anyway, prerender-safe, part of the Unified Toolchain for Flow.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"!*.test.js"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@uniflowed/core": "0.
|
|
32
|
-
"@uniflowed/react": "0.
|
|
31
|
+
"@uniflowed/core": "0.3.0",
|
|
32
|
+
"@uniflowed/react": "0.3.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=19"
|