Function useStack

  • A custom hook for managing a stack of items.

    Type Parameters

    • Item

      Type of the stack elements.

    Parameters

    • initialValues: Stack<Item> = []

      Initial values for the stack.

    Returns {
        add: ((item) => void);
        clear: (() => void);
        isEmpty: boolean;
        peek: (() => unknown);
        remove: (() => unknown);
        size: number;
        stack: unknown[];
    }

    • add: ((item) => void)
        • (item): void
        • Add an item to the end of the stack.

          Parameters

          • item: Item

            The item to push.

          Returns void

    • clear: (() => void)
        • (): void
        • Empty the whole stack.

          Returns void

    • isEmpty: boolean

      A boolean to state if the stack is empty or not.

    • peek: (() => unknown)
        • (): unknown
        • Peek at the last item in the stack without removing it.

          Returns unknown

          The last item in the stack, or undefined if the stack is empty.

    • remove: (() => unknown)
        • (): unknown
        • Remove an item from the tail of the stack.

          Returns unknown

          The item removed.

    • size: number

      The current size of the stack.

    • stack: unknown[]

Generated using TypeDoc