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 anotherswap– swap items positionsapply– 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
UseListStateHandlers type
@mantine/hooks package exports UseListStateHandlers. It is a generic type
that contains all handlers from useListState hook. It can be used to type
handlers in your components.
UseListStateHandlers type:
The type is useful when you want to pass use-list-state handlers to child components
as a prop:
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:
Definition
Exported types
UseListStateHandlers type is exported from @mantine/hooks package,
you can import it in your application: