Skip to main content

Toast Manager

from v9.3

ToastManager manages toast state independently of any specific rendering host. The package also exports toastManager, a shared instance for applications that do not need an isolated toast queue.

Use it when application code needs to enqueue, dismiss, or observe toast messages without coupling that logic to a React component or a deck.gl widget.

Usage​

import {ToastManager, toastManager, type ToastKind, type ToastRequest} from '@deck.gl-community/panels';

API​

new ToastManager(maxVisibleToasts?)​

Creates an isolated toast manager. The optional argument controls the maximum number of visible toasts; it defaults to three.

const isolatedToastManager = new ToastManager(5);

toastManager.toast(request)​

Adds a toast and returns its generated id.

const toastId = toastManager.toast({
type: 'info',
title: 'Loaded',
message: 'Style resolved successfully.'
});

toastManager.dismiss(toastId)​

Dismisses one toast by id.

toastManager.clear()​

Dismisses all visible toasts.

toastManager.getToasts()​

Returns the current visible toast entries.

toastManager.subscribe(listener)​

Subscribes to toast updates and returns an unsubscribe callback.

const unsubscribe = toastManager.subscribe((toasts) => {
console.log(toasts);
});

Types​

type ToastKind = 'info' | 'warning' | 'error';

type ToastRequest = {
type: ToastKind;
title?: string;
message: string;
key?: string;
};

Remarks​

  • Toasts are capped to a small visible stack.
  • Duplicate key values replace the previous toast instead of appending.
  • Auto-dismiss timing depends on type.
  • Rendering can be handled by any host that subscribes to toastManager.