Registry / testing / use-async-queue

use-async-queue

JSON →
library3.0.1jsnpmunverified

A React hook for managing async queues with concurrency control, retries, and cancellation. Version 3.0.1 (stable) ships TypeScript types, supports React 18.3.1+, and is ESM-only. Key differentiators: lightweight (no dependencies beyond React), declarative API using hook state, and built-in retry with exponential backoff. Alternative to TanStack Query for simpler queue scenarios.

npm install use-async-queue
INSTALL
IMPORT
SIG · USE-ASYNC-QUEUE
U
use-async-queue
testingjavascriptv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useAsyncQueue
import { useAsyncQueue } from 'use-async-queue'
import useAsyncQueue from 'use-async-queue'
Named export only; no default export available.
QueueItem
import { QueueItem } from 'use-async-queue'
TypeScript type for queue item objects.
useAsyncQueue (CommonJS)
const { useAsyncQueue } = require('use-async-queue')
const useAsyncQueue = require('use-async-queue')
CJS destructured require is needed because it's a named export.

Shows basic usage: create a queue with concurrency 2 and retry config, enqueue an async fetch, and display queue status.

import { useAsyncQueue } from 'use-async-queue'; function App() { const { enqueue, dequeue, items, isProcessing } = useAsyncQueue({ concurrency: 2, retry: { maxAttempts: 3, delay: 1000 }, }); const handleClick = () => { enqueue( async () => { const res = await fetch('/api/data'); return res.json(); }, { id: 'fetch-data', priority: 1 } ); }; return ( <div> <button onClick={handleClick}>Enqueue</button> <div>Processing: {isProcessing ? 'yes' : 'no'}</div> <ul> {items.map(item => ( <li key={item.id}>{item.status}</li> ))} </ul> </div> ); }
Debug
Known issues
breakingv3 drops support for React <18.3.1 and CommonJS
fix
Upgrade to React 18.3.1 or later; use ESM imports.
affects: >=3.0.0
breakingv2.x had different API (options object vs hook arguments)
fix
Migrate to v3 hook signature: useAsyncQueue({ concurrency, retry }).
affects: <3.0.0
deprecatedcancelQueue() removed in v3; use clear() instead
fix
Replace cancelQueue() with clear() from returned methods.
affects: >=3.0.0
gotchaenqueued functions must return a Promise or be async
fix
Ensure all functions passed to enqueue() are async or return a Promise.
affects: >=0.0.0
Errors
Common errors & fixes
Uncaught TypeError: Cannot destructure property 'enqueue' of '(0 , import_use_async_queue.useAsyncQueue)(...)' as it is undefined.
Using default import instead of named import (common in bundler configs that don't support named exports from ESM).
fix
Change import to named import: import { useAsyncQueue } from 'use-async-queue'
Error: useAsyncQueue must be used within a React component.
Calling the hook outside of a React function component or custom hook.
fix
Move the hook call into a functional component or a custom hook that is called from a component.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
reactrequiredpeer dependency for hooks
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
use-async-queue — npm install use-async-queue · libregistry