Usage
use-list-state hook provides an API to work with list state:
API
use-list-state takes array as single argument and returns list values and handlers to change them in tuple, similar to react's useState hook.
Hook provides handlers to work with array data:
- append– add items to the end of the list
- prepend– add items to the start of the list
- pop– remove last item
- shift– remove first item
- insert– insert items at given index
- remove– remove items at given indices
- reorder– move item from one position to another
- apply– apply given function to all items in the list
- applyWhere- apply given function to selective items using condition
- setItem– replace item at given index
- setItemProp– set item property at given index
- setState– set list state with react action
- filter- filter values with callback function
Indeterminate state checkbox example
TypeScript
Definition
Set item type
By default, use-list-state will use type from initialValues.
If you init hook with empty array, you must specify item type: