Use list state
GitHubReact hook for immutable list state updates, including insertion, removal, reordering, and item updates.
Installation
bash
pnpm dlx shadcn@latest add @cs/use-list-stateUsage
tsx
import { useListState } from "@/hooks/cs/use-list-state"tsx
const [items, handlers] = useListState(["first"])
handlers.append("second")API Reference
UseListStateReturnValue
tsx
type UseListStateReturnValue = [T[], UseListStateHandlers<T>]useListState
Manages an array with immutable update helpers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| initialValue * | T[] | (() => T[]) | - | - |
Returns: UseListStateReturnValue<T>