Skip to Content
ohooks

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

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useQueue.json

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
queue
array
Current items in the queue from front to back.
size
number
Number of items currently in the queue.
first
union
First item at the front of the queue, or undefined if empty.
last
union
Last item at the back of the queue, or undefined if empty.
isEmpty
union
Whether the queue contains zero items.
enqueue
function
Appends one or more items to the back of the queue.
dequeue
function
Removes and returns the item at the front of the queue.
peek
function
Returns the item at the front of the queue without removing it.
clear
function
Removes all items from the queue.
reset
function
Restores the queue to its initialValue.