Skip to content

useQueue

Hook that manages a queue

state
medium
test coverage
Last changed: 7 months ago

Installation

Library
CLI
Manual
typescript
import { useQueue } from '@siberiacancode/reactuse';

Usage

typescript
const { queue, add, remove, clear, first, last, size } = useQueue([1, 2, 3]);

Demo

Api

Parameters

NameTypeDefaultNote
initialValue?Value[][]The initial value of the queue

Returns

UseQueueReturn

Type declaration

typescript
export interface UseQueueReturn<Value> {
  /** Get the first element of the queue */
  first: Value;
  /** Get the last element of the queue */
  last: Value;
  /** The current queue */
  queue: Value[];
  /** Get the size of the queue */
  size: number;
  /** Add an element to the queue */
  add: (element: Value) => void;
  /** Clear the queue */
  clear: () => void;
  /** Remove an element from the queue */
  remove: () => Value;
}

Source

SourceDemo

Contributors

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.