useArrayState
Manages your array state
Usage
useArrayState provides an API to work with array state:
API
useArrayState takes an array as a single argument and
returns an array 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 arrayprepend– add items to the start of the arraypop– 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 arrayapplyWhere- apply given function to selective items using conditionsetItem– replace item at given indexsetItemProp– set item property at given indexsetState– set array state with react actionfilter- filter values with callback function
UseArrayStateFns type
hook-master package exports UseArrayStateFns. It is a generic type
that contains all handlers from useArrayState hook. It can be used to type
handlers in your components.
UseArrayStateFns type:
Set item type
By default, useArrayState will use type from initialValues.
If you call the hook with an empty array, you must specify item type: