use-queue
Usage
use-queue limits the amount of data in current state and places the rest of it in a queue. For example, in @asuikit/notifications package amount of notifications that is currently displayed is limited and other new notifications are added to queue and displayed once available space appears.
API
Hook accepts single argument – configuration object with keys:
initialValues
– optional initial values (divided between state and queue according to limit), defaults to empty arraylimit
– maximum amount of items that state can include, every next item after limit is exceeded is put in queue
Return value:
state
– current statequeue
– current queueadd
– add any amount 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 queue
Example
Example of use-queue hook usage in Mantine notifications system. By default only 5 notifications can be displayed at a time, rest are added to queue.
TypeScript
By default, hook will get types information from initialValues
automatically:
If you do not provide initialValues
, pass in type for state item:
TypeScript
Definition
Item type
Item type is set automatically based on initialValues
,
if you do not have initialValue
it is required to pass in item type: