daily-toolset
Version:
A lightweight, versatile collection of TypeScript utility functions for everyday development needs. Simplify and streamline your Node.js, React, and Next.js projects with a powerful suite of well-organized helpers for strings, arrays, dates, objects, and
35 lines (34 loc) • 1.67 kB
TypeScript
/**
* A React hook for managing a list of items. The returned list can be modified
* using the following methods:
*
* - `apply`: Applies a callback function to each item in the list.
* - `applyWhere`: Applies a callback function to each item in the list that
* matches the condition.
* - `append`: Adds new items to the end of the list.
* - `filter`: Removes all items from the list that do not match the condition.
* - `insert`: Inserts items at the specified index in the list.
* - `pop`: Removes the last item from the list.
* - `prepend`: Inserts items at the beginning of the list.
* - `remove`: Removes the items at the specified indices from the list.
* - `set`: Replaces the current list with the new items.
* - `shift`: Removes the first item from the list.
*
* The hook returns an array with two elements. The first element is the list
* itself, and the second element is an object with the above methods.
*
* @param initialValue The initial value of the list.
* @returns A tuple containing the list and an object with the above methods.
*/
export declare function useList<T>(initialValue: T[]): readonly [T[], {
readonly apply: (callback: (value: T) => T) => void;
readonly applyWhere: (condition: (item: T) => boolean, fn: (value: T) => T) => void;
readonly append: (...items: T[]) => void;
readonly filter: (fn: (value: T) => boolean) => void;
readonly insert: (index: number, ...items: T[]) => void;
readonly pop: () => void;
readonly prepend: (...items: T[]) => void;
readonly remove: (...indices: number[]) => void;
readonly set: (...items: T[]) => void;
readonly shift: () => void;
}];