Skip to Content
ohooks

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

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useList.json

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
set
Dispatch<SetStateAction<array>>
Standard React state setter for replacing or updating the array
push
function
Appends one or more items to the end of the list
updateAt
function
Replaces the item at index (supports negative indices)
insertAt
function
Inserts an item at index (clamped to list bounds, supports negative indices)
removeAt
function
Removes the item at index (supports negative indices)
filter
function
Keeps only items that satisfy the predicate function
sort
function
Sorts the list in place (immutably) using an optional comparator
clear
function
Empties the list
reset
function
Resets the list back to initialValue