MCPcopy Create free account
hub / github.com/adobe/react-spectrum / add

Method add

packages/react-stately/src/toast/useToastState.ts:117–130  ·  view source on GitHub ↗

Adds a new toast to the queue.

(content: T, options: ToastOptions = {})

Source from the content-addressed store, hash-verified

115
116 /** Adds a new toast to the queue. */
117 add(content: T, options: ToastOptions = {}): string {
118 let toastKey = '_' + Math.random().toString(36).slice(2);
119 let toast: QueuedToast<T> = {
120 ...options,
121 content,
122 key: toastKey,
123 timer: options.timeout ? new Timer(() => this.close(toastKey), options.timeout) : undefined
124 };
125
126 this.queue.unshift(toast);
127
128 this.updateVisibleToasts('add');
129 return toastKey;
130 }
131
132 /**
133 * Closes a toast.

Callers

nothing calls this directly

Calls 4

closeMethod · 0.95
updateVisibleToastsMethod · 0.95
sliceMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected