preact-missing-hooks 1.0.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/Readme.md ADDED
@@ -0,0 +1,111 @@
1
+ # Preact Missing Hooks
2
+
3
+ A lightweight, extendable collection of missing React-like hooks for Preact, starting with `useTransition`.
4
+
5
+ ---
6
+
7
+ ## ✨ Features
8
+
9
+ * **🔄 `useTransition`**: Mimics React's `useTransition` for deferring state updates.
10
+ * ✅ Fully TypeScript compatible
11
+ * 📦 Bundled with Microbundle
12
+ * 🔌 Easily extensible — more hooks can be added in future
13
+ * ⚡ Zero dependencies (except `preact`)
14
+
15
+ ---
16
+
17
+ ## 📦 Installation
18
+
19
+ ```bash
20
+ npm install preact-missing-hooks
21
+ ```
22
+
23
+ Ensure `preact` is installed in your project:
24
+
25
+ ```bash
26
+ npm install preact
27
+ ```
28
+
29
+ ---
30
+
31
+ ## 🔧 Usage
32
+
33
+ ```tsx
34
+ import { useTransition } from 'preact-missing-hooks';
35
+
36
+ const Example = () => {
37
+ const [isPending, startTransition] = useTransition();
38
+
39
+ const handleClick = () => {
40
+ startTransition(() => {
41
+ // Expensive update here
42
+ });
43
+ };
44
+
45
+ return (
46
+ <button onClick={handleClick} disabled={isPending}>
47
+ {isPending ? 'Loading...' : 'Click me'}
48
+ </button>
49
+ );
50
+ };
51
+ ```
52
+
53
+ ---
54
+
55
+ ## 🔍 API: `useTransition()`
56
+
57
+ Returns a tuple:
58
+
59
+ * `startTransition(fn: () => void)` — schedules a low-priority update
60
+ * `isPending: boolean` — `true` while the transition is in progress
61
+
62
+ ---
63
+
64
+ ## 🛠 Built With
65
+
66
+ * [Preact](https://preactjs.com)
67
+ * [Microbundle](https://github.com/developit/microbundle)
68
+ * [TypeScript](https://www.typescriptlang.org/)
69
+
70
+ ---
71
+
72
+ ## 🧩 Future Hooks (Planned)
73
+
74
+ * `useDebounce`
75
+ * `useThrottle`
76
+ * `useIdleCallback`
77
+
78
+ ---
79
+
80
+ ## 📤 Publishing
81
+
82
+ Build before publishing:
83
+
84
+ ```bash
85
+ npm run build
86
+ ```
87
+
88
+ Then:
89
+
90
+ ```bash
91
+ npm publish --access public
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 📝 License
97
+
98
+ ISC © [Prakhar Dubey](https://github.com/your-profile)
99
+
100
+ ---
101
+
102
+ ## 📬 Contributing
103
+
104
+ Feel free to open issues or submit PRs to suggest or contribute additional hooks!
105
+
106
+ ---
107
+
108
+ ## 📎 Related
109
+
110
+ * [React useTransition Docs](https://react.dev/reference/react/useTransition)
111
+ * [Preact Documentation](https://preactjs.com/guide/v10/getting-started/)
@@ -0,0 +1 @@
1
+ export * from './useTransition';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ var e=require("preact/hooks");exports.useTransition=function(){var r=e.useState(!1),n=r[0],t=r[1];return[e.useCallback(function(e){t(!0),Promise.resolve().then(function(){e(),t(!1)})},[]),n]};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/useTransition.ts"],"sourcesContent":["import { useState, useCallback } from 'preact/hooks';\r\n\r\n/**\r\n * Mimics React's useTransition hook in Preact.\r\n * @returns [startTransition, isPending]\r\n */\r\nexport function useTransition(): [startTransition: (callback: () => void) => void, isPending: boolean] {\r\n const [isPending, setIsPending] = useState(false);\r\n\r\n const startTransition = useCallback((callback: () => void) => {\r\n setIsPending(true);\r\n Promise.resolve().then(() => {\r\n callback();\r\n setIsPending(false);\r\n });\r\n }, []);\r\n\r\n return [startTransition, isPending];\r\n}\r\n"],"names":["_useState","useState","isPending","setIsPending","useCallback","callback","Promise","resolve","then"],"mappings":"oDAMgB,WACd,IAAAA,EAAkCC,EAAQA,UAAC,GAApCC,EAASF,KAAEG,EAAYH,EAAA,GAU9B,MAAO,CARiBI,EAAWA,YAAC,SAACC,GACnCF,GAAa,GACbG,QAAQC,UAAUC,KAAK,WACrBH,IACAF,GAAa,EACf,EACF,EAAG,IAEsBD,EAC3B"}
@@ -0,0 +1,2 @@
1
+ import{useState as o,useCallback as r}from"preact/hooks";function n(){var n=o(!1),t=n[0],e=n[1];return[r(function(o){e(!0),Promise.resolve().then(function(){o(),e(!1)})},[]),t]}export{n as useTransition};
2
+ //# sourceMappingURL=index.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.module.js","sources":["../src/useTransition.ts"],"sourcesContent":["import { useState, useCallback } from 'preact/hooks';\r\n\r\n/**\r\n * Mimics React's useTransition hook in Preact.\r\n * @returns [startTransition, isPending]\r\n */\r\nexport function useTransition(): [startTransition: (callback: () => void) => void, isPending: boolean] {\r\n const [isPending, setIsPending] = useState(false);\r\n\r\n const startTransition = useCallback((callback: () => void) => {\r\n setIsPending(true);\r\n Promise.resolve().then(() => {\r\n callback();\r\n setIsPending(false);\r\n });\r\n }, []);\r\n\r\n return [startTransition, isPending];\r\n}\r\n"],"names":["useTransition","_useState","useState","isPending","setIsPending","useCallback","callback","Promise","resolve","then"],"mappings":"yDAMgB,SAAAA,IACd,IAAAC,EAAkCC,GAAS,GAApCC,EAASF,KAAEG,EAAYH,EAAA,GAU9B,MAAO,CARiBI,EAAY,SAACC,GACnCF,GAAa,GACbG,QAAQC,UAAUC,KAAK,WACrBH,IACAF,GAAa,EACf,EACF,EAAG,IAEsBD,EAC3B"}
@@ -0,0 +1,2 @@
1
+ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("preact/hooks")):"function"==typeof define&&define.amd?define(["exports","preact/hooks"],o):o((e||self).preactMissingHooks={},e.hooks)}(this,function(e,o){e.useTransition=function(){var e=o.useState(!1),n=e[0],t=e[1];return[o.useCallback(function(e){t(!0),Promise.resolve().then(function(){e(),t(!1)})},[]),n]}});
2
+ //# sourceMappingURL=index.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.umd.js","sources":["../src/useTransition.ts"],"sourcesContent":["import { useState, useCallback } from 'preact/hooks';\r\n\r\n/**\r\n * Mimics React's useTransition hook in Preact.\r\n * @returns [startTransition, isPending]\r\n */\r\nexport function useTransition(): [startTransition: (callback: () => void) => void, isPending: boolean] {\r\n const [isPending, setIsPending] = useState(false);\r\n\r\n const startTransition = useCallback((callback: () => void) => {\r\n setIsPending(true);\r\n Promise.resolve().then(() => {\r\n callback();\r\n setIsPending(false);\r\n });\r\n }, []);\r\n\r\n return [startTransition, isPending];\r\n}\r\n"],"names":["_useState","useState","isPending","setIsPending","useCallback","callback","Promise","resolve","then"],"mappings":"6SAMgB,WACd,IAAAA,EAAkCC,EAAQA,UAAC,GAApCC,EAASF,KAAEG,EAAYH,EAAA,GAU9B,MAAO,CARiBI,EAAWA,YAAC,SAACC,GACnCF,GAAa,GACbG,QAAQC,UAAUC,KAAK,WACrBH,IACAF,GAAa,EACf,EACF,EAAG,IAEsBD,EAC3B"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Mimics React's useTransition hook in Preact.
3
+ * @returns [startTransition, isPending]
4
+ */
5
+ export declare function useTransition(): [startTransition: (callback: () => void) => void, isPending: boolean];
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "preact-missing-hooks",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight, extendable collection of missing React-like hooks for Preact",
5
+ "author": "Prakhar Dubey",
6
+ "license": "ISC",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.module.js",
9
+ "types": "dist/index.d.ts",
10
+ "source": "src/index.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.module.js",
14
+ "require": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ },
17
+ "./useTransition": {
18
+ "import": "./dist/useTransition.module.js",
19
+ "require": "./dist/useTransition.js",
20
+ "types": "./dist/useTransition.d.ts"
21
+ }
22
+ },
23
+ "scripts": {
24
+ "build": "microbundle",
25
+ "dev": "microbundle watch",
26
+ "prepublishOnly": "npm run build",
27
+ "test": "echo \"Error: no test specified\" && exit 1"
28
+ },
29
+ "keywords": [
30
+ "preact",
31
+ "hooks",
32
+ "usetransition",
33
+ "react-hooks",
34
+ "microbundle",
35
+ "typescript",
36
+ "preact-hooks"
37
+ ],
38
+ "dependencies": {
39
+ "preact": "^10.26.7"
40
+ },
41
+ "devDependencies": {
42
+ "microbundle": "^0.15.1",
43
+ "typescript": "^5.8.3"
44
+ },
45
+ "peerDependencies": {
46
+ "preact": ">=10.0.0"
47
+ }
48
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './useTransition';
@@ -0,0 +1,19 @@
1
+ import { useState, useCallback } from 'preact/hooks';
2
+
3
+ /**
4
+ * Mimics React's useTransition hook in Preact.
5
+ * @returns [startTransition, isPending]
6
+ */
7
+ export function useTransition(): [startTransition: (callback: () => void) => void, isPending: boolean] {
8
+ const [isPending, setIsPending] = useState(false);
9
+
10
+ const startTransition = useCallback((callback: () => void) => {
11
+ setIsPending(true);
12
+ Promise.resolve().then(() => {
13
+ callback();
14
+ setIsPending(false);
15
+ });
16
+ }, []);
17
+
18
+ return [startTransition, isPending];
19
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES6",
4
+ "module": "ESNext",
5
+ "jsx": "react",
6
+ "jsxFactory": "h",
7
+ "moduleResolution": "Node",
8
+ "esModuleInterop": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "strict": true,
11
+ "skipLibCheck": true,
12
+ "declaration": true,
13
+ "outDir": "dist"
14
+ },
15
+ "include": ["src"]
16
+ }
17
+