UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

28 lines (27 loc) 1.2 kB
export interface QueueMethods<T> { /** Adds an item to the end of the queue. */ add: (item: T) => void; /** Removes the item from the front of the queue. */ remove: () => void; /** Returns the item at the front of the queue without removing it. Returns undefined if the queue is empty. */ peek: () => T | undefined; /** The current number of items in the queue. */ size: number; /** The first item in the queue (same as peek), or undefined if empty. */ first: T | undefined; /** The last item in the queue, or undefined if empty. */ last: T | undefined; /** Read-only access to the entire queue array. */ queue: readonly T[]; /** Removes all items from the queue. */ clear: () => void; } /** * Manages a stateful queue (First-In, First-Out). * Provides methods to add, remove, peek, and clear the queue, along with its current state. * * @template T The type of items the queue will hold. * @param initialQueue An optional initial array of items to populate the queue. * @returns An object containing the queue state and methods to interact with it. */ export declare function useQueue<T>(initialQueue?: T[]): QueueMethods<T>;