Native Toast
API Reference

toast

Imperative API methods for creating, updating, and dismissing toasts.

The toast object is the primary API for interacting with NativeToast. Import it once and use it anywhere.

import { toast } from '@ncrft/native-toast';

Methods

toast(message, options?)

Generic blank toast — no built-in icon.

ParameterTypeDefault
messageToastMessage
optionsToastOptions{ duration: 4000 }

Returns: string — the toast ID

const id = toast('Hello world');

toast.success(message, options?)

Success toast with animated green checkmark SVG.

ParameterTypeDefault
messageToastMessage
optionsToastOptions{ duration: 2000 }

Returns: string — the toast ID


toast.error(message, options?)

Error toast with animated red X-mark SVG.

ParameterTypeDefault
messageToastMessage
optionsToastOptions{ duration: 4000 }

Returns: string — the toast ID


toast.loading(message, options?)

Loading toast with native ActivityIndicator spinner. Never auto-dismisses.

ParameterTypeDefault
messageToastMessage
optionsToastOptions{ duration: Infinity }

Returns: string — the toast ID

const id = toast.loading('Uploading…');
// later:
toast.dismiss(id);

toast.custom(message, options?)

Custom toast — no built-in icon. Message can be any ReactNode.

ParameterTypeDefault
messageToastMessage
optionsToastOptions{ duration: 4000 }

Returns: string — the toast ID


toast.dismiss(toastId?)

Triggers exit animation, then removes the toast after the cleanup delay.

ParameterTypeDescription
toastIdstring | undefinedSpecific toast to dismiss. Omit to dismiss all toasts.

Returns: void

toast.dismiss('t_3');   // dismiss specific toast
toast.dismiss();        // dismiss all

toast.remove(toastId?)

Immediately removes a toast with no exit animation.

ParameterTypeDescription
toastIdstring | undefinedSpecific toast to remove. Omit to remove all toasts.

Returns: void


toast.promise(promise, messages, options?)

Shows a loading toast, then transitions to success or error based on promise resolution.

ParameterTypeDescription
promisePromise<T> | (() => Promise<T>)The promise to track, or a function returning one
messages{ loading, success, error }Messages for each state
optionsToastOptionsOptional toast options

Returns: void

toast.promise(
  fetch('/api/data'),
  {
    loading: 'Fetching…',
    success: 'Data loaded!',
    error: 'Fetch failed',
  },
  { id: 'fetch-toast' }
);

Toast IDs

  • Auto-incrementing: t_1, t_2, t_3, …
  • Custom: pass id in options → toast.loading('…', { id: 'my-id' })

Upsert Behavior

Creating a toast with an existing id updates the existing toast instead of creating a duplicate. This is useful for promise flows:

const id = 'upload';

toast.loading('Uploading…', { id });
// Later, same ID → updates the existing toast:
toast.success('Upload complete!', { id });

On this page