use-queue limits the amount of data in current state and places the rest of it in a queue. For example, in @mantine/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.
Hook accepts single argument – configuration object with keys:
initialValues– optional initial values (divided between state and queue according to limit), defaults to empty array
limit– maximum amount of items that state can include, every next item after limit is exceeded is put in queue
state– current state
queue– current queue
add– add any amount of items to state or queue
update– apply given function to all items in state and queue, use it to filter, modify or add items
cleanQueue– remove all items from queue
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.
By default, hook will get types information from
If you do not provide
initialValues, pass in type for state item:
Item type is set automatically based on
if you do not have
initialValue it is required to pass in item type: