Skip to main content

Dismiss by ID

Signature

toast.dismiss(id: string): void

Parameters

id
string
required
The toast ID to dismiss

Example

// Custom toasts return their ID
const toastId = toast.custom(<MyToast />);

// Later, dismiss it
toast.dismiss(toastId);

Use case: Persistent toast with manual dismiss

const toastId = toast.info("Processing...", {
  duration: Infinity,  // Never auto-dismiss
  dismissible: false,  // Can't swipe to dismiss
});

// When processing is complete
processData().then(() => {
  toast.dismiss(toastId);
  toast.success("Processing complete!");
});

Use case: Dismiss from custom content

toast.custom(({ id, dismiss }) => (
  <View style={{ flexDirection: 'row', padding: 16 }}>
    <Text>Custom message</Text>
    <Button title="Close" onPress={dismiss} />
    {/* Or use the ID directly */}
    <Button title="Close Alt" onPress={() => toast.dismiss(id)} />
  </View>
));

Dismiss all

Signature

toast.dismissAll(): void

Example

// Dismiss all visible toasts
toast.dismissAll();

Use case: Clear all on navigation

import { useEffect } from 'react';
import { toast } from 'react-native-bread';

function LoginScreen() {
  useEffect(() => {
    // Clear all toasts when entering login screen
    return () => {
      toast.dismissAll();
    };
  }, []);
  
  return <LoginForm />;
}

Use case: Clear on logout

const handleLogout = async () => {
  // Clear all existing toasts
  toast.dismissAll();
  
  await logout();
  
  toast.success("Logged out", "See you next time!");
};

Use case: Error boundary

import { Component } from 'react';
import { toast } from 'react-native-bread';

class ErrorBoundary extends Component {
  componentDidCatch(error, errorInfo) {
    // Clear all toasts on critical error
    toast.dismissAll();
    
    // Show error toast
    toast.error("Something went wrong", {
      description: error.message,
      duration: 10000,
    });
  }
  
  render() {
    return this.props.children;
  }
}

Examples combining both

Dismiss old, show new

let currentToastId: string | null = null;

const showStatus = (message: string) => {
  // Dismiss previous status toast if exists
  if (currentToastId) {
    toast.dismiss(currentToastId);
  }
  
  // Show new status
  currentToastId = toast.custom(
    <StatusToast message={message} />
  );
};

showStatus("Connecting...");
showStatus("Connected!");  // Dismisses previous toast

Batch operations

const processItems = async (items) => {
  const toastIds = items.map(item => 
    toast.info(`Processing ${item.name}`, {
      duration: Infinity,
    })
  );
  
  try {
    await Promise.all(items.map(processItem));
    
    // Dismiss all processing toasts
    toastIds.forEach(id => toast.dismiss(id));
    
    // Show success
    toast.success("All items processed!");
  } catch (error) {
    // Clear all on error
    toast.dismissAll();
    toast.error("Processing failed", error.message);
  }
};

Conditional dismissal

const toastIds = new Set<string>();

// Track toasts
const showTrackedToast = (message: string) => {
  const id = toast.custom(<MyToast message={message} />);
  toastIds.add(id);
  return id;
};

// Dismiss only tracked toasts
const dismissTrackedToasts = () => {
  toastIds.forEach(id => toast.dismiss(id));
  toastIds.clear();
};

// Dismiss everything
const dismissEverything = () => {
  toast.dismissAll();
  toastIds.clear();
};

Notes

  • toast.dismiss(id) triggers the exit animation before removing the toast
  • toast.dismissAll() dismisses all visible toasts immediately
  • Only toast.custom() returns a toast ID - other toast methods (success, error, info, promise) do not return IDs
  • If you need to track and dismiss specific non-custom toasts, use the id option:
    toast.success("Saved", {
      id: "save-toast",
      description: "Changes saved"
    });
    
    // Later
    toast.dismiss("save-toast");
    
  • Dismissing a toast that doesn’t exist (or was already dismissed) is a no-op and won’t cause errors

Build docs developers (and LLMs) love