useList ​
Hook that provides state and helper methods to manage a list of items
utilities
test coverage
Last changed: last month
Installation ​
Library
CLI
Manual
typescript
import { useList } from '@siberiacancode/reactuse';
Usage ​
typescript
const { value, set, push, removeAt, insertAt, updateAt, clear } = useList();
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
initialList | Item[] | (() => Item[]) | - | The initial list of items |
Returns
UseListReturn
Type declaration ​
typescript
export interface UseListReturn<Item> {
/** The current list of items */
value: Item[];
/** Clears the list */
clear: () => void;
/** Inserts an item at the specified index */
insertAt: (insertAtIndex: number, item: Item) => void;
/** Adds an item to the list */
push: (item: Item) => void;
/** Removes an item from the list */
removeAt: (removeAtIndex: number) => void;
/** Sets the list of items */
set: (list: Item[]) => void;
/** Updates an item at the specified index */
updateAt: (updateAtIndex: number, item: Item) => void;
}
Source ​
Source • DemoContributors ​
D
A
H