A beautiful, lightweight, and customizable toast notification library for React applications with full TypeScript support.
- 🎨 Beautiful, modern design with smooth animations
- 🎯 TypeScript support out of the box
- 🚀 Lightweight with zero dependencies
- 🎭 Multiple toast types (success, error, loading, default)
- 📍 Flexible positioning options
- 🔄 Promise-based toasts
- ⚡ Easy to use API similar to react-hot-toast
- 🎨 Customizable styling
npm install planet-toast- Add the Toaster component to your app:
import React from "react";
import { Toaster } from "planet-toast";
function App() {
return (
<div>
{/* Your app content */}
<Toaster />
</div>
);
}- Start creating toasts:
import { toast } from "planet-toast";
// Basic toast
toast("Hello World!");
// Success toast
toast.success("Profile updated successfully!");
// Error toast
toast.error("Something went wrong!");
// Loading toast
toast.loading("Uploading...");Create different types of toasts:
import { toast } from "planet-toast";
// Default toast
toast("Hello World!");
// Success toast
toast.success("Operation completed!");
// Error toast
toast.error("Something went wrong!");
// Loading toast (doesn't auto-dismiss)
toast.loading("Loading...");
// Custom duration
toast("Custom duration", { duration: 6000 });
// Custom ID (useful for updating)
toast.loading("Uploading...", { id: "upload" });
toast.success("Upload complete!", { id: "upload" });Handle promises with automatic toast updates:
const uploadPromise = fetch("/api/upload", {
method: "POST",
body: formData,
});
toast.promise(uploadPromise, {
loading: "Uploading file...",
success: "File uploaded successfully!",
error: "Upload failed. Please try again.",
});// Dismiss a specific toast
const toastId = toast("Hello");
toast.dismiss(toastId);
// Remove a toast immediately
toast.remove(toastId);Configure the toast container:
<Toaster
position="top-right"
reverseOrder={false}
gutter={8}
containerStyle={{}}
toastOptions={{
duration: 4000,
}}
/>position: Toast position (top-left,top-center,top-right,bottom-left,bottom-center,bottom-right)reverseOrder: Reverse the order of toastsgutter: Space between toasts in pixelscontainerStyle: Custom styles for the containertoastOptions: Default options for all toasts
Planet Toast is built with TypeScript and provides full type safety:
import { ToastType, ToastOptions, ToastPosition } from "planet-toast";
const customToast = (
message: string,
type: ToastType,
options?: ToastOptions
) => {
// Your custom logic
};import { useToasts } from "planet-toast";
function ToastManager() {
const toasts = useToasts();
return (
<div>
<p>Active toasts: {toasts.length}</p>
</div>
);
}<Toaster
containerStyle={{
top: "20px",
fontSize: "16px",
}}
toastOptions={{
duration: 5000,
}}
/>MIT © Planet Toast
Contributions are welcome! Please feel free to submit a Pull Request.