function useAsyncQueuerState<TValue>(options): [() => Promise<TValue>[], AsyncQueuer<TValue>]
function useAsyncQueuerState<TValue>(options): [() => Promise<TValue>[], AsyncQueuer<TValue>]
Defined in: async-queuer/useAsyncQueuerState.ts:53
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:
• TValue
AsyncQueuerOptions<TValue> = {}
[() => Promise<TValue>[], AsyncQueuer<TValue>]
// Create a queue with state management
const [queueItems, asyncQueuer] = useAsyncQueuerState({
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] = useAsyncQueuerState({
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.