useToast @astryx-svelte/core v0.3.0 · Toast

Usage

Hook for showing toast notifications from anywhere in your component tree. Returns a function that accepts toast options and shows the notification. Works automatically with LayerProvider or self-mounts a fallback viewport.
ts
import { Toast } from '@astryx-svelte/core';

Best practices

GuidancePractices
DoUse for transient success/error feedback that does not require user action.
DoSet uniqueID to deduplicate toasts from rapid user actions.
Don'tUse for critical errors that require acknowledgment; use AlertDialog instead.
Don'tCall useToast in the same component that renders LayerProvider; it must be called from a child component inside the provider.

Returns

FieldTypeDefaultDescription
showToast (options: ToastOptions) => () => voidShow a toast notification. Returns a dismiss function. Options include body (ReactNode), type ("info" | "error"), isAutoHide, autoHideDuration, endContent, uniqueID, and collisionBehavior.

useToast() returns this function itself — ShowToastFn, i.e. (options: ToastOptions) => ToastDismissFn. Upstream returns it the same way; the name is its doc table’s label for the single return value, not a member to read off an object.