use-list-state
Manages array state
Import
Source
Docs
Package
Usage
use-list-state
provides an API to work with list state:
API
use-list-state
takes an array as a single argument and
returns a list of values and handlers to change them in a tuple, similar to useState
hook.
The hook provides handlers to work with array data:
append
– add items to the end of the listprepend
– add items to the start of the listpop
– remove last itemshift
– remove first iteminsert
– insert items at given indexremove
– remove items at given indicesreorder
– move item from one position to anotherapply
– apply given function to all items in the listapplyWhere
- apply given function to selective items using conditionsetItem
– replace item at given indexsetItemProp
– set item property at given indexsetState
– set list state with react actionfilter
- filter values with callback function
Indeterminate state checkbox example
Definition
Set item type
By default, use-list-state
will use type from initialValues
.
If you call the hook with an empty array, you must specify item type: