Usage
use-queue
limits the number of data in current state and places the rest of it in a queue.
For example, in @mantine/notifications package number of
notifications that is currently displayed is limited and other new notifications are added to the queue and displayed once
available space appears.
API
The hook accepts one argument – a configuration object with keys:
initialValues
– optional initial values (divided between state and queue according to limit), defaults to empty arraylimit
– maximum number of items that state can include, every next item after the limit is exceeded is put in queue
Return value:
state
– current statequeue
– current queueadd
– add any number of items to state or queueupdate
– apply given function to all items in state and queue, use it to filter, modify or add itemscleanQueue
– remove all items from the queue
Set item type
By default, the hook will get types information from initialValues
automatically:
If you do not provide initialValues
, pass in type for state item: