useList
Manages an array state with immutable helper methods for pushing, inserting, updating, removing, filtering, and sorting items.
Loading preview...
The useList hook manages an array state and returns a tuple of [list, actions] with memoized helpers (push, insertAt, updateAt, removeAt, filter, sort, clear, and reset) that perform immutable updates.
Installation
Usage
Examples
Todo List CRUD Operations
Use push, updateAt, removeAt, and clear to manipulate list items without writing manual array spread boilerplate.
Sorting, Filtering, and Resetting
Use filter, sort, and reset to transform the list or revert it back to initialValue.
API Reference
UseListActions
Memoized array mutation helpers returned as the second tuple element.
Property
Specification
setDispatch<SetStateAction<array>>
Standard React state setter for replacing or updating the array
Full Signature
pushfunction
Appends one or more items to the end of the list
Full Signature
Parameters
...itemsT[]updateAtfunction
Replaces the item at
index (supports negative indices)Full Signature
Parameters
indexnumberitemTinsertAtfunction
Inserts an item at
index (clamped to list bounds, supports negative indices)Full Signature
Parameters
indexnumberitemTremoveAtfunction
Removes the item at
index (supports negative indices)Full Signature
Parameters
indexnumberfilterfunction
Keeps only items that satisfy the predicate function
Full Signature
Parameters
predicate(value: T, index: number, array: T[]) => booleansortfunction
Sorts the list in place (immutably) using an optional comparator
Full Signature
Parameters
compareFn?(a: T, b: T) => numberclearfunction
Empties the list
Full Signature
resetfunction
Resets the list back to
initialValueFull Signature