preact-missing-hooks 4.6.0 → 4.8.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/llm.package.json CHANGED
@@ -1,151 +1,134 @@
1
1
  {
2
2
  "name": "preact-missing-hooks",
3
- "version": "4.4.0",
3
+ "version": "4.6.0",
4
4
  "description": "A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.",
5
5
  "exports": {
6
6
  "useTransition": {
7
7
  "type": "function",
8
- "description": "Hook that tracks a pending state for an async operation, providing a boolean `isPending` and a `startTransition` function to wrap state updates. Useful for deferring non-urgent UI updates so the interface stays responsive during slow operations.",
8
+ "description": "React hook that provides a transition state to coordinate updates that may be delayed, allowing components to render fallback UI while waiting.",
9
9
  "hook": true,
10
- "params": "callback: () => void",
11
- "returns": "{ isPending: boolean, startTransition: (callback: () => void) => void }",
12
- "example": "const [isPending, startTransition] = useTransition(); startTransition(() => { /* heavy work */ });"
10
+ "params": "config?: { timeoutMs?: number }",
11
+ "returns": "[isPending: boolean, startTransition: (callback: () => void) => void]"
13
12
  },
14
13
  "useMutationObserver": {
15
14
  "type": "function",
16
- "description": "Hook that creates a MutationObserver on a DOM element and calls a callback when mutations occur. Ideal for reacting to DOM changes like attributes, child list, or subtree modifications without manual cleanup.",
15
+ "description": "React hook that observes DOM mutations on a target element, invoking a callback when mutations occur.",
17
16
  "hook": true,
18
- "params": "target: Element, callback: (mutations: MutationRecord[]) => void, options?: MutationObserverInit",
19
- "returns": "void",
20
- "example": "useMutationObserver(ref.current, (m) => console.log(m), { childList: true });"
17
+ "params": "target: Element | null, callback: (mutations: MutationRecord[]) => void, options?: MutationObserverInit"
21
18
  },
22
19
  "useEventBus": {
23
20
  "type": "function",
24
- "description": "Hook that subscribes to a PubSub event bus, returning an emitter object to publish events and an array of listeners for specific topics. Simplifies decoupled communication between components.",
21
+ "description": "React hook that provides access to a shared event bus for pub/sub communication between components.",
25
22
  "hook": true,
26
23
  "params": "none",
27
- "returns": "{ emit: (topic: string, data: any) => void, on: (topic: string, fn: (data: any) => void) => () => void }",
28
- "example": "const { emit, on } = useEventBus(); on('update', (d) => console.log(d)); emit('update', { foo: 'bar' });"
24
+ "returns": "{ emit: (event: string, data?: any) => void, on: (event: string, handler: (data?: any) => void) => void, off: (event: string, handler: (data?: any) => void) => void }"
29
25
  },
30
26
  "useWrappedChildren": {
31
27
  "type": "function",
32
- "description": "Hook that wraps child components or elements with additional logic or styling, returning a wrapped version of the children. Useful for injecting context, props, or wrappers without altering the original structure.",
28
+ "description": "React hook that wraps child components with additional props or context, useful for injecting shared data.",
33
29
  "hook": true,
34
- "params": "children: ReactNode, wrapper: (child: ReactNode) => ReactNode",
35
- "returns": "ReactNode",
36
- "example": "const wrapped = useWrappedChildren(children, (c) => <div className='wrapper'>{c}</div>);"
30
+ "params": "children: ReactNode, wrapperProps?: object",
31
+ "returns": "ReactNode"
37
32
  },
38
33
  "usePreferredTheme": {
39
34
  "type": "function",
40
- "description": "Hook that detects the user's preferred color scheme (light/dark) via `prefers-color-scheme` media query and returns the current theme. Automatically updates when the system theme changes.",
35
+ "description": "React hook that detects and returns the user's preferred color scheme (light/dark) from system or media query.",
41
36
  "hook": true,
42
37
  "params": "none",
43
- "returns": "'light' | 'dark' | 'no-preference'",
44
- "example": "const theme = usePreferredTheme();"
38
+ "returns": "'light' | 'dark' | 'no-preference'"
45
39
  },
46
40
  "useNetworkState": {
47
41
  "type": "function",
48
- "description": "Hook that tracks the browser's online/offline status and optionally network type, returning an object with `online` boolean and `networkType`. Reacts to connectivity changes for offline-aware UIs.",
42
+ "description": "React hook that returns the current network connection status (online/offline) and connectivity details.",
49
43
  "hook": true,
50
44
  "params": "none",
51
- "returns": "{ online: boolean, networkType?: string }",
52
- "example": "const { online, networkType } = useNetworkState();"
45
+ "returns": "{ online: boolean, since?: Date, type?: string, effectiveType?: string, downlink?: number, rtt?: number }"
53
46
  },
54
47
  "useClipboard": {
55
48
  "type": "function",
56
- "description": "Hook that provides async read/write access to the system clipboard, returning `write` and `read` functions. Useful for copy/paste features without directly using the Clipboard API.",
49
+ "description": "React hook that provides access to the system clipboard for reading and writing text content.",
57
50
  "hook": true,
58
51
  "params": "none",
59
- "returns": "{ write: (data: string) => Promise<void>, read: () => Promise<string> }",
60
- "example": "const { write } = useClipboard(); write('hello');"
52
+ "returns": "{ text: string | null, write: (text: string) => Promise<void> }"
61
53
  },
62
54
  "useRageClick": {
63
55
  "type": "function",
64
- "description": "Hook that detects rapid, repeated clicks on an element and triggers a callback, often used to implement 'rage click' UX patterns like retrying failed actions. Configurable for click count and delay.",
56
+ "description": "React hook that detects rapid repeated clicks on an element, useful for triggering special actions or preventing accidental triggers.",
65
57
  "hook": true,
66
- "params": "callback: () => void, options?: { count?: number, delay?: number }",
67
- "returns": "void",
68
- "example": "useRageClick(() => retry(), { count: 3, delay: 500 });"
58
+ "params": "onClick: (event: MouseEvent) => void, threshold?: number",
59
+ "returns": "void"
69
60
  },
70
61
  "useThreadedWorker": {
71
62
  "type": "function",
72
- "description": "Creates a reusable thread pool for executing CPU-intensive tasks in Web Workers. Useful for offloading heavy computations without blocking the UI thread, returning a handle to dispatch jobs and retrieve results.",
63
+ "description": "Creates a Web Worker from a script or function and provides a thread-safe interface to run tasks in parallel. Ideal for CPU-intensive operations that should not block the UI thread.",
73
64
  "hook": true,
74
- "params": "options: { maxThreads?: number, workerUrl?: string }, callback?: (result: any) => void",
75
- "returns": "WorkerPool instance with methods like dispatch() and terminate()",
65
+ "params": "workerSource: string | Function, options?: { autoTerminate?: boolean }",
66
+ "returns": "{ run: (data: any) => Promise<any>, terminate: () => void }",
76
67
  "sideEffect": false,
77
- "example": "const pool = useThreadedWorker({ maxThreads: 4 }); pool.dispatch(heavyTask);"
68
+ "example": "const { run, terminate } = useThreadedWorker(workerScript); run({ data }).then(result => console.log(result));"
78
69
  },
79
70
  "useIndexedDB": {
80
71
  "type": "function",
81
- "description": "Provides a React hook to interact with IndexedDB for client-side storage. Handles opening databases, transactions, and CRUD operations, making it easy to persist data offline with automatic error handling.",
72
+ "description": "Provides a reactive interface to IndexedDB for storing and retrieving structured data in the browser. Useful for offline-first apps or caching large datasets beyond localStorage limits.",
82
73
  "hook": true,
83
- "params": "storeName: string, options?: { version?: number, upgrade?: (db: IDBDatabase) => void }",
84
- "returns": "{ get, set, delete, clear, getAll }",
74
+ "params": "dbName: string, storeName: string, options?: { version?: number }",
75
+ "returns": "{ get: (key: string) => Promise<any>, set: (key: string, value: any) => Promise<void>, delete: (key: string) => Promise<void>, clear: () => Promise<void> }",
85
76
  "sideEffect": false,
86
- "example": "const { get, set } = useIndexedDB('myStore'); set('key', data);"
77
+ "example": "const { get, set } = useIndexedDB('myApp', 'users'); set('user1', userData); const user = await get('user1');"
87
78
  },
88
79
  "useWebRTCIP": {
89
80
  "type": "function",
90
- "description": "Detects and retrieves the client's public and local IP addresses using WebRTC. Useful for network diagnostics or peer-to-peer connections, returning an array of detected IPs with metadata about each.",
81
+ "description": "Detects the local IP address of the client using WebRTC without establishing a peer connection. Helpful for network-aware applications or WebRTC debugging.",
91
82
  "hook": true,
92
- "params": "options?: { timeout?: number }",
93
- "returns": "{ ips: string[], localIps: string[], publicIps: string[] }",
83
+ "params": "none",
84
+ "returns": "Promise<string[]>",
94
85
  "sideEffect": false,
95
- "example": "const { ips } = useWebRTCIP(); console.log('Detected IPs:', ips);"
86
+ "example": "const ips = await useWebRTCIP(); console.log('Local IPs:', ips);"
96
87
  },
97
88
  "useWasmCompute": {
98
89
  "type": "function",
99
- "description": "Loads and executes WebAssembly modules for high-performance computation. Ideal for tasks like image processing or cryptography, providing a simple interface to call exported functions with typed arrays.",
90
+ "description": "Loads and runs WebAssembly modules for high-performance computations in the browser. Best for heavy numeric processing or cryptographic operations where JavaScript is too slow.",
100
91
  "hook": true,
101
- "params": "wasmUrl: string, imports?: Record<string, any>",
102
- "returns": "WasmModule instance with methods to call exported functions",
92
+ "params": "wasmModule: ArrayBuffer | string, importObject?: object",
93
+ "returns": "{ run: (method: string, ...args: any[]) => any, free: () => void }",
103
94
  "sideEffect": false,
104
- "example": "const wasm = useWasmCompute('/compute.wasm'); wasm.multiply(2, 3);"
95
+ "example": "const { run } = useWasmCompute(wasmBytes); const result = run('computeHash', input);"
105
96
  },
106
97
  "useWorkerNotifications": {
107
98
  "type": "function",
108
- "description": "Manages push notifications from Web Workers, enabling background tasks to trigger user notifications. Useful for long-running processes that need to alert users upon completion without blocking the main thread.",
109
- "hook": true,
110
- "params": "workerUrl: string, notificationOptions?: NotificationOptions",
111
- "returns": "{ postMessage, onNotification, requestPermission }",
112
- "sideEffect": false,
113
- "example": "const { postMessage } = useWorkerNotifications('/worker.js'); postMessage({ type: 'start' });"
114
- },
115
- "useLLMMetadata": {
116
- "type": "function",
117
- "description": "Extracts and processes metadata from LLVM bitcode or compiled modules. Useful for analyzing compiled code structure, retrieving function signatures, and understanding module dependencies in development tools.",
99
+ "description": "Registers a service worker and manages push notifications with permission handling. Useful for real-time updates or background messaging in progressive web apps.",
118
100
  "hook": true,
119
- "params": "bitcode: Uint8Array, options?: { extractFunctions?: boolean }",
120
- "returns": "{ functions: string[], metadata: Record<string, any> }",
101
+ "params": "swUrl: string, options?: { permission?: 'default' | 'granted' | 'denied' }",
102
+ "returns": "{ subscribe: () => Promise<boolean>, unsubscribe: () => Promise<void>, isSubscribed: boolean }",
121
103
  "sideEffect": false,
122
- "example": "const { functions } = useLLMMetadata(bitcodeBuffer); console.log('Functions:', functions);"
104
+ "example": "const { subscribe } = useWorkerNotifications('/sw.js'); await subscribe();"
123
105
  },
124
106
  "useRefPrint": {
125
107
  "type": "function",
126
- "description": "Provides a hook to manage print operations for DOM elements referenced via refs. Useful for triggering print dialogs or generating print layouts for specific components without affecting the entire page.",
108
+ "description": "Provides a reference to a DOM element and a method to print its contents. Useful for printing specific sections of a page without affecting the entire document.",
127
109
  "hook": true,
128
- "params": "ref: React.RefObject<HTMLElement>, options?: { media?: string }",
129
- "returns": "{ print, isPrinting: boolean }",
110
+ "params": "none",
111
+ "returns": "{ ref: React.RefObject<any>, print: () => void }",
130
112
  "sideEffect": false,
131
- "example": "const { print } = useRefPrint(ref); print();"
113
+ "example": "const { ref, print } = useRefPrint(); return <div ref={ref}>Content to print</div>;"
132
114
  },
133
115
  "useRBAC": {
134
116
  "type": "function",
135
- "description": "Implements Role-Based Access Control (RBAC) for React applications. Manages user roles and permissions, providing utilities to check access and conditionally render components based on defined policies.",
117
+ "description": "Manages role-based access control by checking user permissions against defined roles. Ideal for securing components or routes based on user authorization levels.",
136
118
  "hook": true,
137
- "params": "roles: string[], permissions: string[], options?: { defaultRole?: string }",
138
- "returns": "{ hasRole, hasPermission, canAccess: (resource: string) => boolean }",
119
+ "params": "userRoles: string[], permissions: { [role: string]: string[] }",
120
+ "returns": "{ hasPermission: (action: string) => boolean, roles: string[] }",
139
121
  "sideEffect": false,
140
- "example": "const { canAccess } = useRBAC(userRoles, userPermissions); if (canAccess('admin')) { /* render admin UI */ }"
122
+ "example": "const { hasPermission } = useRBAC(user.roles, permissionMap); if (hasPermission('edit')) { /* show edit button */ }"
141
123
  },
142
124
  "usePrefetch": {
143
125
  "type": "function",
144
- "description": "A custom hook that prefetches a resource or module in a Preact application, typically used to improve performance by loading data or code in advance. It accepts a URL or module identifier and returns a loading state or prefetch result, enabling developers to optimize user experience by reducing latency.",
126
+ "description": "Prefetches resources like scripts, styles, or API data to improve perceived performance. Best for predictive loading when user is likely to navigate to a specific route.",
145
127
  "hook": true,
146
- "params": "url: string, options?: { priority?: 'high' | 'low', timeout?: number }",
147
- "returns": "Promise<void> | { loading: boolean, error?: Error }",
148
- "example": "const [loading, error] = usePrefetch('/api/data', { priority: 'high' });"
128
+ "params": "resources: string[] | { [key: string]: string }",
129
+ "returns": "{ loading: boolean, error: Error | null }",
130
+ "sideEffect": false,
131
+ "example": "const { loading } = usePrefetch(['/api/data', '/static/style.css']); if (loading) { /* show spinner */ }"
149
132
  }
150
133
  },
151
134
  "hooks": [
@@ -162,7 +145,6 @@
162
145
  "useWebRTCIP",
163
146
  "useWasmCompute",
164
147
  "useWorkerNotifications",
165
- "useLLMMetadata",
166
148
  "useRefPrint",
167
149
  "useRBAC",
168
150
  "usePrefetch"
@@ -174,7 +156,10 @@
174
156
  "generatedBy": "hayagriva-llm@1.2.0",
175
157
  "mode": "ai",
176
158
  "summary": "Preact-Missing-Hooks is a lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps. It bridges the gap between Preact and React's hook ecosystem while adding innovative hooks for advanced web features like WebRTC, WebAssembly, IndexedDB, and more.",
177
- "sideEffects": [],
159
+ "sideEffects": [
160
+ "reads process.env",
161
+ "modifies DOM"
162
+ ],
178
163
  "keywords": [
179
164
  "preact",
180
165
  "hooks",
package/llm.package.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Package: preact-missing-hooks
2
- Version: 4.4.0
2
+ Version: 4.6.0
3
3
 
4
4
  Description:
5
5
  A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.
@@ -33,6 +33,10 @@ Use cases:
33
33
  - Tracking worker notifications and task execution in real-time
34
34
  - Retrieving local WebRTC IP addresses for signaling or diagnostics
35
35
 
36
+ Side effects:
37
+ - reads process.env
38
+ - modifies DOM
39
+
36
40
  Keywords:
37
41
  preact, hooks, react-hooks, useTransition, useMutationObserver, useEventBus, useWrappedChildren, usePreferredTheme, useNetworkState, useClipboard, useRageClick, useThreadedWorker, useIndexedDB, useWebRTCIP, useWasmCompute, useWorkerNotifications, useLLMMetadata, useRefPrint, useRBAC, usePrefetch, typescript, modern-web, web-development, frontend, ui-components
38
42
 
@@ -44,23 +48,22 @@ Related packages:
44
48
  preact, react, react-hooks, preact/hooks, preact/compat
45
49
 
46
50
  Exports:
47
- - useClipboard (Hook) : Hook that provides async read/write access to the system clipboard, returning `write` and `read` functions. Useful for copy/paste features without directly using the Clipboard API. — params: none — returns: { write: (data: string) => Promise<void>, read: () => Promise<string> } — e.g. const { write } = useClipboard(); write('hello');
48
- - useEventBus (Hook) : Hook that subscribes to a PubSub event bus, returning an emitter object to publish events and an array of listeners for specific topics. Simplifies decoupled communication between components. — params: none — returns: { emit: (topic: string, data: any) => void, on: (topic: string, fn: (data: any) => void) => () => void } e.g. const { emit, on } = useEventBus(); on('update', (d) => console.log(d)); emit('update', { foo: 'bar' });
49
- - useIndexedDB (Hook) : Provides a React hook to interact with IndexedDB for client-side storage. Handles opening databases, transactions, and CRUD operations, making it easy to persist data offline with automatic error handling. — params: storeName: string, options?: { version?: number, upgrade?: (db: IDBDatabase) => void } returns: { get, set, delete, clear, getAll } — e.g. const { get, set } = useIndexedDB('myStore'); set('key', data);
50
- - useLLMMetadata (Hook) : Extracts and processes metadata from LLVM bitcode or compiled modules. Useful for analyzing compiled code structure, retrieving function signatures, and understanding module dependencies in development tools. — params: bitcode: Uint8Array, options?: { extractFunctions?: boolean } — returns: { functions: string[], metadata: Record<string, any> } — e.g. const { functions } = useLLMMetadata(bitcodeBuffer); console.log('Functions:', functions);
51
- - useMutationObserver (Hook) : Hook that creates a MutationObserver on a DOM element and calls a callback when mutations occur. Ideal for reacting to DOM changes like attributes, child list, or subtree modifications without manual cleanup. — params: target: Element, callback: (mutations: MutationRecord[]) => void, options?: MutationObserverInit returns: void — e.g. useMutationObserver(ref.current, (m) => console.log(m), { childList: true });
52
- - useNetworkState (Hook) : Hook that tracks the browser's online/offline status and optionally network type, returning an object with `online` boolean and `networkType`. Reacts to connectivity changes for offline-aware UIs. — params: none — returns: { online: boolean, networkType?: string } — e.g. const { online, networkType } = useNetworkState();
53
- - usePreferredTheme (Hook) : Hook that detects the user's preferred color scheme (light/dark) via `prefers-color-scheme` media query and returns the current theme. Automatically updates when the system theme changes. — params: none — returns: 'light' | 'dark' | 'no-preference' — e.g. const theme = usePreferredTheme();
54
- - usePrefetch (Hook) : A custom hook that prefetches a resource or module in a Preact application, typically used to improve performance by loading data or code in advance. It accepts a URL or module identifier and returns a loading state or prefetch result, enabling developers to optimize user experience by reducing latency. — params: url: string, options?: { priority?: 'high' | 'low', timeout?: number } — returns: Promise<void> | { loading: boolean, error?: Error } — e.g. const [loading, error] = usePrefetch('/api/data', { priority: 'high' });
55
- - useRageClick (Hook) : Hook that detects rapid, repeated clicks on an element and triggers a callback, often used to implement 'rage click' UX patterns like retrying failed actions. Configurable for click count and delay.params: callback: () => void, options?: { count?: number, delay?: number } returns: void — e.g. useRageClick(() => retry(), { count: 3, delay: 500 });
56
- - useRBAC (Hook) : Implements Role-Based Access Control (RBAC) for React applications. Manages user roles and permissions, providing utilities to check access and conditionally render components based on defined policies. — params: roles: string[], permissions: string[], options?: { defaultRole?: string } — returns: { hasRole, hasPermission, canAccess: (resource: string) => boolean } — e.g. const { canAccess } = useRBAC(userRoles, userPermissions); if (canAccess('admin')) { /* render admin UI */ }
57
- - useRefPrint (Hook) : Provides a hook to manage print operations for DOM elements referenced via refs. Useful for triggering print dialogs or generating print layouts for specific components without affecting the entire page. — params: ref: React.RefObject<HTMLElement>, options?: { media?: string } — returns: { print, isPrinting: boolean } — e.g. const { print } = useRefPrint(ref); print();
58
- - useThreadedWorker (Hook) : Creates a reusable thread pool for executing CPU-intensive tasks in Web Workers. Useful for offloading heavy computations without blocking the UI thread, returning a handle to dispatch jobs and retrieve results. — params: options: { maxThreads?: number, workerUrl?: string }, callback?: (result: any) => void — returns: WorkerPool instance with methods like dispatch() and terminate() e.g. const pool = useThreadedWorker({ maxThreads: 4 }); pool.dispatch(heavyTask);
59
- - useTransition (Hook) : Hook that tracks a pending state for an async operation, providing a boolean `isPending` and a `startTransition` function to wrap state updates. Useful for deferring non-urgent UI updates so the interface stays responsive during slow operations. — params: callback: () => void — returns: { isPending: boolean, startTransition: (callback: () => void) => void } — e.g. const [isPending, startTransition] = useTransition(); startTransition(() => { /* heavy work */ });
60
- - useWasmCompute (Hook) : Loads and executes WebAssembly modules for high-performance computation. Ideal for tasks like image processing or cryptography, providing a simple interface to call exported functions with typed arrays. — params: wasmUrl: string, imports?: Record<string, any> — returns: WasmModule instance with methods to call exported functions — e.g. const wasm = useWasmCompute('/compute.wasm'); wasm.multiply(2, 3);
61
- - useWebRTCIP (Hook) : Detects and retrieves the client's public and local IP addresses using WebRTC. Useful for network diagnostics or peer-to-peer connections, returning an array of detected IPs with metadata about each. — params: options?: { timeout?: number } — returns: { ips: string[], localIps: string[], publicIps: string[] } — e.g. const { ips } = useWebRTCIP(); console.log('Detected IPs:', ips);
62
- - useWorkerNotifications (Hook) : Manages push notifications from Web Workers, enabling background tasks to trigger user notifications. Useful for long-running processes that need to alert users upon completion without blocking the main thread. — params: workerUrl: string, notificationOptions?: NotificationOptions — returns: { postMessage, onNotification, requestPermission } — e.g. const { postMessage } = useWorkerNotifications('/worker.js'); postMessage({ type: 'start' });
63
- - useWrappedChildren (Hook) : Hook that wraps child components or elements with additional logic or styling, returning a wrapped version of the children. Useful for injecting context, props, or wrappers without altering the original structure. — params: children: ReactNode, wrapper: (child: ReactNode) => ReactNode — returns: ReactNode — e.g. const wrapped = useWrappedChildren(children, (c) => <div className='wrapper'>{c}</div>);
51
+ - useClipboard (Hook) : React hook that provides access to the system clipboard for reading and writing text content. — params: none — returns: { text: string | null, write: (text: string) => Promise<void> }
52
+ - useEventBus (Hook) : React hook that provides access to a shared event bus for pub/sub communication between components. — params: none — returns: { emit: (event: string, data?: any) => void, on: (event: string, handler: (data?: any) => void) => void, off: (event: string, handler: (data?: any) => void) => void }
53
+ - useIndexedDB (Hook) : Provides a reactive interface to IndexedDB for storing and retrieving structured data in the browser. Useful for offline-first apps or caching large datasets beyond localStorage limits. — params: dbName: string, storeName: string, options?: { version?: number } — returns: { get: (key: string) => Promise<any>, set: (key: string, value: any) => Promise<void>, delete: (key: string) => Promise<void>, clear: () => Promise<void> } — e.g. const { get, set } = useIndexedDB('myApp', 'users'); set('user1', userData); const user = await get('user1');
54
+ - useMutationObserver (Hook) : React hook that observes DOM mutations on a target element, invoking a callback when mutations occur. — params: target: Element | null, callback: (mutations: MutationRecord[]) => void, options?: MutationObserverInit
55
+ - useNetworkState (Hook) : React hook that returns the current network connection status (online/offline) and connectivity details. — params: none returns: { online: boolean, since?: Date, type?: string, effectiveType?: string, downlink?: number, rtt?: number }
56
+ - usePreferredTheme (Hook) : React hook that detects and returns the user's preferred color scheme (light/dark) from system or media query. — params: none — returns: 'light' | 'dark' | 'no-preference'
57
+ - usePrefetch (Hook) : Prefetches resources like scripts, styles, or API data to improve perceived performance. Best for predictive loading when user is likely to navigate to a specific route. — params: resources: string[] | { [key: string]: string } — returns: { loading: boolean, error: Error | null } — e.g. const { loading } = usePrefetch(['/api/data', '/static/style.css']); if (loading) { /* show spinner */ }
58
+ - useRageClick (Hook) : React hook that detects rapid repeated clicks on an element, useful for triggering special actions or preventing accidental triggers. — params: onClick: (event: MouseEvent) => void, threshold?: number — returns: void
59
+ - useRBAC (Hook) : Manages role-based access control by checking user permissions against defined roles. Ideal for securing components or routes based on user authorization levels. params: userRoles: string[], permissions: { [role: string]: string[] } returns: { hasPermission: (action: string) => boolean, roles: string[] } e.g. const { hasPermission } = useRBAC(user.roles, permissionMap); if (hasPermission('edit')) { /* show edit button */ }
60
+ - useRefPrint (Hook) : Provides a reference to a DOM element and a method to print its contents. Useful for printing specific sections of a page without affecting the entire document. — params: none — returns: { ref: React.RefObject<any>, print: () => void } — e.g. const { ref, print } = useRefPrint(); return <div ref={ref}>Content to print</div>;
61
+ - useThreadedWorker (Hook) : Creates a Web Worker from a script or function and provides a thread-safe interface to run tasks in parallel. Ideal for CPU-intensive operations that should not block the UI thread. — params: workerSource: string | Function, options?: { autoTerminate?: boolean } — returns: { run: (data: any) => Promise<any>, terminate: () => void } — e.g. const { run, terminate } = useThreadedWorker(workerScript); run({ data }).then(result => console.log(result));
62
+ - useTransition (Hook) : React hook that provides a transition state to coordinate updates that may be delayed, allowing components to render fallback UI while waiting. — params: config?: { timeoutMs?: number } — returns: [isPending: boolean, startTransition: (callback: () => void) => void]
63
+ - useWasmCompute (Hook) : Loads and runs WebAssembly modules for high-performance computations in the browser. Best for heavy numeric processing or cryptographic operations where JavaScript is too slow. — params: wasmModule: ArrayBuffer | string, importObject?: object — returns: { run: (method: string, ...args: any[]) => any, free: () => void } — e.g. const { run } = useWasmCompute(wasmBytes); const result = run('computeHash', input);
64
+ - useWebRTCIP (Hook) : Detects the local IP address of the client using WebRTC without establishing a peer connection. Helpful for network-aware applications or WebRTC debugging. — params: none returns: Promise<string[]> — e.g. const ips = await useWebRTCIP(); console.log('Local IPs:', ips);
65
+ - useWorkerNotifications (Hook) : Registers a service worker and manages push notifications with permission handling. Useful for real-time updates or background messaging in progressive web apps. — params: swUrl: string, options?: { permission?: 'default' | 'granted' | 'denied' } — returns: { subscribe: () => Promise<boolean>, unsubscribe: () => Promise<void>, isSubscribed: boolean } — e.g. const { subscribe } = useWorkerNotifications('/sw.js'); await subscribe();
66
+ - useWrappedChildren (Hook) : React hook that wraps child components with additional props or context, useful for injecting shared data. — params: children: ReactNode, wrapperProps?: object — returns: ReactNode
64
67
 
65
68
  Hooks:
66
69
  - useTransition
@@ -76,7 +79,6 @@ Hooks:
76
79
  - useWebRTCIP
77
80
  - useWasmCompute
78
81
  - useWorkerNotifications
79
- - useLLMMetadata
80
82
  - useRefPrint
81
83
  - useRBAC
82
84
  - usePrefetch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "preact-missing-hooks",
3
- "version": "4.6.0",
3
+ "version": "4.8.0",
4
4
  "description": "A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.",
5
5
  "author": "Prakhar Dubey",
6
6
  "license": "MIT",
@@ -97,6 +97,16 @@
97
97
  "import": "./dist/usePrefetch.module.js",
98
98
  "require": "./dist/usePrefetch.js"
99
99
  },
100
+ "./usePoll": {
101
+ "types": "./dist/usePoll.d.ts",
102
+ "import": "./dist/usePoll.module.js",
103
+ "require": "./dist/usePoll.js"
104
+ },
105
+ "./useDeviceData": {
106
+ "types": "./dist/useDeviceData.d.ts",
107
+ "import": "./dist/useDeviceData.module.js",
108
+ "require": "./dist/useDeviceData.js"
109
+ },
100
110
  "./react": {
101
111
  "types": "./dist/index.d.ts",
102
112
  "import": "./dist/react.module.js",
@@ -104,7 +114,7 @@
104
114
  }
105
115
  },
106
116
  "scripts": {
107
- "build": "microbundle --alias react=preact/compat && npm run build:react && node scripts/generate-entry.cjs",
117
+ "build": "node scripts/ensure-microbundle-patch.cjs && microbundle --alias react=preact/compat && npm run build:react && node scripts/generate-entry.cjs",
108
118
  "llm:generate": "hayagriva-llm generate --mode ai --include-src --verbose",
109
119
  "build:react": "rollup -c scripts/rollup.react.config.cjs",
110
120
  "dev": "microbundle watch",
@@ -117,7 +127,7 @@
117
127
  "lint": "eslint src",
118
128
  "format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
119
129
  "format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\"",
120
- "prepare": "husky",
130
+ "prepare": "husky && node scripts/ensure-microbundle-patch.cjs",
121
131
  "clean:cache": "node -e \"try{require('fs').rmSync('node_modules/.cache',{recursive:true,force:true});console.log('Cache cleared');}catch(e){}\"",
122
132
  "size": "npm run clean:cache && npm run build && size-limit"
123
133
  },
@@ -150,6 +160,8 @@
150
160
  "useNetworkState",
151
161
  "useClipboard",
152
162
  "usePrefetch",
163
+ "usePoll",
164
+ "useDeviceData",
153
165
  "useRageClick",
154
166
  "rage click",
155
167
  "sentry",
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Patches microbundle to pass clean: true to rollup-plugin-typescript2.
3
+ * In rpt2, "clean" disables the RollingCache (noCache), avoiding EPERM rename
4
+ * failures on Windows during UMD/CJS/ESM builds.
5
+ */
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+
9
+ const cliPath = path.join(
10
+ __dirname,
11
+ "..",
12
+ "node_modules",
13
+ "microbundle",
14
+ "dist",
15
+ "cli.js",
16
+ );
17
+
18
+ if (!fs.existsSync(cliPath)) {
19
+ console.warn(
20
+ "ensure-microbundle-patch: microbundle not installed, skipping patch",
21
+ );
22
+ process.exit(0);
23
+ }
24
+
25
+ const src = fs.readFileSync(cliPath, "utf8");
26
+ const marker = "clean: true,";
27
+
28
+ if (src.includes(marker)) {
29
+ process.exit(0);
30
+ }
31
+
32
+ const needle =
33
+ "(useTypescript || emitDeclaration) && typescript__default['default']({";
34
+ const replacement = `${needle} clean: true,`;
35
+
36
+ if (!src.includes(needle)) {
37
+ console.error(
38
+ "ensure-microbundle-patch: microbundle cli.js format changed; update the patch script",
39
+ );
40
+ process.exit(1);
41
+ }
42
+
43
+ fs.writeFileSync(cliPath, src.replace(needle, replacement), "utf8");
44
+ console.log(
45
+ "Patched microbundle (rollup-plugin-typescript2 clean:true for Windows EPERM)",
46
+ );
package/src/index.ts CHANGED
@@ -15,3 +15,5 @@ export * from "./useLLMMetadata";
15
15
  export * from "./useRefPrint";
16
16
  export * from "./useRBAC";
17
17
  export * from "./usePrefetch";
18
+ export * from "./usePoll";
19
+ export * from "./useDeviceData";