useQueue
Manages a reactive FIFO (first-in, first-out) queue in React state.
Loading preview...
The useQueue hook manages a reactive first-in, first-out (FIFO) queue in React state, exposing enqueue, dequeue, peek, clear, reset, and live first, last, and size properties.
Installation
Usage
Examples
Notification Toast Queue
Add incoming messages to the back of the queue with enqueue and dismiss the oldest message from the front with dequeue.
Batch Enqueueing Items
Pass multiple items to enqueue at once to append a batch to the end of the queue.
API Reference
UseQueueReturn
Queue state, boundary getters, and FIFO mutation helpers returned by the hook.
Property
Specification
queuearray
Current items in the queue from front to back.
Full Signature
sizenumber
Number of items currently in the queue.
firstunion
First item at the front of the queue, or
undefined if empty.Full Signature
lastunion
Last item at the back of the queue, or
undefined if empty.Full Signature
isEmptyunion
Whether the queue contains zero items.
Full Signature
enqueuefunction
Appends one or more items to the back of the queue.
Full Signature
Parameters
...itemsT[]dequeuefunction
Removes and returns the item at the front of the queue.
Full Signature
peekfunction
Returns the item at the front of the queue without removing it.
Full Signature
clearfunction
Removes all items from the queue.
Full Signature
resetfunction
Restores the queue to its
initialValue.Full Signature