File: useQueuedValue.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
React
Version
Latest
Search...
+ K
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
Framework
React
Version
Latest
Menu
Getting Started
Guides
API Reference
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference
Debouncer Examples
Throttler Examples
Rate Limiter Examples
Queue Examples
Batcher Examples
TanStack Query Examples
On this page
Copy Markdown
Function: useQueuedValue()
==========================
ts
function useQueuedValue<TValue, TSelected>(
initialValue,
options,
selector?): [TValue, ReactQueuer<TValue, TSelected>];
function useQueuedValue<TValue, TSelected>(
initialValue,
options,
selector?): [TValue, ReactQueuer<TValue, TSelected>];
Defined in: react-pacer/src/queuer/useQueuedValue.ts:103
A React hook that creates a queued value that processes state changes in order with an optional delay. This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially.
The queued value will process changes in the order they are received, with optional delays between processing each change. This is useful for handling state updates that need to be processed in a specific order, like animations or sequential UI updates.
The hook returns a tuple containing:
State Management and Selector
-----------------------------
The hook uses TanStack Store for reactive state management via the underlying queuer instance. The selector parameter allows you to specify which queuer state changes will trigger a re-render, optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
By default, there will be no reactive state subscriptions and you must opt-in to state tracking by providing a selector function. This prevents unnecessary re-renders and gives you full control over when your component updates. Only when you provide a selector will the component re-render when the selected state values change.
Available queuer state properties:
Type Parameters
---------------
### TValue
TValue
TSelected extends Pick<QueuerState<TValue>, "items"> = Pick<QueuerState<TValue>, "items">
Parameters
----------
### initialValue
TValue
QueuerOptions<TValue> = {}
(state) => TSelected
[TValue, ReactQueuer
<TValue, TSelected>]
tsx
// Default behavior - no reactive state subscriptions
const [value, queuer] = useQueuedValue(initialValue, {
wait: 500, // Wait 500ms between processing each change
started: true // Start processing immediately
});
// Opt-in to re-render when queue processing state changes (optimized for loading indicators)
const [value, queuer] = useQueuedValue(
initialValue,
{ wait: 500, started: true },
(state) => ({
isRunning: state.isRunning,
isIdle: state.isIdle,
status: state.status,
pendingTick: state.pendingTick
})
);
// Opt-in to re-render when queue contents change (optimized for displaying queue status)
const [value, queuer] = useQueuedValue(
initialValue,
{ wait: 500, started: true },
(state) => ({
size: state.size,
isEmpty: state.isEmpty,
isFull: state.isFull
})
);
// Opt-in to re-render when execution metrics change (optimized for stats display)
const [value, queuer] = useQueuedValue(
initialValue,
{ wait: 500, started: true },
(state) => ({
executionCount: state.executionCount,
expirationCount: state.expirationCount,
rejectionCount: state.rejectionCount
})
);
// Add changes to the queue
const handleChange = (newValue) => {
queuer.addItem(newValue);
};
// Control the queue
const pauseProcessing = () => {
queuer.stop();
};
const resumeProcessing = () => {
queuer.start();
};
// Access the selected queuer state (will be empty object {} unless selector provided)
const { size, isRunning, executionCount } = queuer.state;
// Default behavior - no reactive state subscriptions
const [value, queuer] = useQueuedValue(initialValue, {
wait: 500, // Wait 500ms between processing each change
started: true // Start processing immediately
});
// Opt-in to re-render when queue processing state changes (optimized for loading indicators)
const [value, queuer] = useQueuedValue(
initialValue,
{ wait: 500, started: true },
(state) => ({
isRunning: state.isRunning,
isIdle: state.isIdle,
status: state.status,
pendingTick: state.pendingTick
})
);
// Opt-in to re-render when queue contents change (optimized for displaying queue status)
const [value, queuer] = useQueuedValue(
initialValue,
{ wait: 500, started: true },
(state) => ({
size: state.size,
isEmpty: state.isEmpty,
isFull: state.isFull
})
);
// Opt-in to re-render when execution metrics change (optimized for stats display)
const [value, queuer] = useQueuedValue(
initialValue,
{ wait: 500, started: true },
(state) => ({
executionCount: state.executionCount,
expirationCount: state.expirationCount,
rejectionCount: state.rejectionCount
})
);
// Add changes to the queue
const handleChange = (newValue) => {
queuer.addItem(newValue);
};
// Control the queue
const pauseProcessing = () => {
queuer.stop();
};
const resumeProcessing = () => {
queuer.start();
};
// Access the selected queuer state (will be empty object {} unless selector provided)
const { size, isRunning, executionCount } = queuer.state;
