@prtcl/plonk-hooks 1.0.4 → 1.0.6
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 +44 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
1
|
# @prtcl/plonk-hooks
|
|
2
2
|
|
|
3
|
-
React
|
|
3
|
+
React hook wrappers for [`@prtcl/plonk`](https://www.npmjs.com/package/@prtcl/plonk). Manages timer lifecycle on mount/unmount so you can use plonk's timers and generators directly in components.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm i @prtcl/plonk @prtcl/plonk-hooks
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires React 17–19 as a peer dependency.
|
|
12
|
+
|
|
13
|
+
## Hooks
|
|
14
|
+
|
|
15
|
+
- **`useMetro`** — interval-based timer loop
|
|
16
|
+
- **`useFrames`** — `requestAnimationFrame`-based loop
|
|
17
|
+
- **`usePrevious`** — tracks the previous value of a variable
|
|
18
|
+
|
|
19
|
+
## Quick example
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { useRef } from 'react';
|
|
23
|
+
import { Env } from '@prtcl/plonk';
|
|
24
|
+
import { useFrames } from '@prtcl/plonk-hooks';
|
|
25
|
+
|
|
26
|
+
const env = new Env({ duration: 2000, from: 0, to: 1 });
|
|
27
|
+
|
|
28
|
+
function FadeIn({ children }) {
|
|
29
|
+
const ref = useRef(null);
|
|
30
|
+
|
|
31
|
+
const frames = useFrames(() => {
|
|
32
|
+
if (ref.current) {
|
|
33
|
+
ref.current.style.opacity = `${env.next()}`;
|
|
34
|
+
}
|
|
35
|
+
if (env.done()) {
|
|
36
|
+
frames.stop();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return <div ref={ref}>{children}</div>;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Documentation
|
|
45
|
+
|
|
46
|
+
See the full [API Reference](https://github.com/prtcl/plonk/blob/main/docs/API.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prtcl/plonk-hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "React hook wrappers for plonk",
|
|
5
5
|
"author": "Cory O'Brien <cory@prtcl.cc>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "vitest --browser.name=chrome --browser.headless --watch=false"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@prtcl/plonk": "1.0.
|
|
26
|
+
"@prtcl/plonk": "1.0.6",
|
|
27
27
|
"client-only": "^0.0.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|