function useAsyncQueuedState<TFn>(options): [TFn[], AsyncQueuer<TFn>]
function useAsyncQueuedState<TFn>(options): [TFn[], AsyncQueuer<TFn>]
Defined in: react-pacer/src/async-queuer/useAsyncQueuedState.ts:54
A higher-level React hook that creates an AsyncQueuer instance with built-in state management.
This hook combines an AsyncQueuer with React state to automatically track the queue items. It returns a tuple containing:
The queue can be configured with:
The state will automatically update whenever items are:
• TFn extends AsyncQueuerFn
AsyncQueuerOptions<TFn> = {}
[TFn[], AsyncQueuer<TFn>]
// Create a queue with state management
const [queueItems, asyncQueuer] = useAsyncQueuedState({
concurrency: 2,
maxSize: 100,
started: true
});
// Add items to queue - state updates automatically
asyncQueuer.addItem(async () => {
const result = await fetchData();
return result;
});
// Start processing
asyncQueuer.start();
// Stop processing
asyncQueuer.stop();
// queueItems reflects current queue state
const pendingCount = asyncQueuer.getPendingItems().length;
// Create a queue with state management
const [queueItems, asyncQueuer] = useAsyncQueuedState({
concurrency: 2,
maxSize: 100,
started: true
});
// Add items to queue - state updates automatically
asyncQueuer.addItem(async () => {
const result = await fetchData();
return result;
});
// Start processing
asyncQueuer.start();
// Stop processing
asyncQueuer.stop();
// queueItems reflects current queue state
const pendingCount = asyncQueuer.getPendingItems().length;
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.