A lightweight, customizable, and developer-friendly toast notification system for React.
- π₯ Multiple positions support (
top-right,top-left,bottom-right,bottom-left) - β³ Built-in auto-dismiss with smooth progress bar
- π± Pause on hover
- π¨ Fully customizable with CSS classes
- π¦ Tiny footprint and zero external dependencies
npm install toastware
# or
yarn add toastwareimport { ToastProvider } from "toastware";
function App() {
return (
<ToastProvider>
<YourApp />
</ToastProvider>
);
}You can now use Toastware globally without importing or calling the useToast() hook in your React components.
Simply import the toastware object and start triggering toasts anywhere in your app β even outside React components!
import toastware from "toastware";
function App() {
return (
<div>
<button onClick={() => toastware.success("Operation successful!")}>
Show Success Toast
</button>
<button onClick={() => toastware.error("Something went wrong!")}>
Show Error Toast
</button>
<button onClick={() => toastware.addToast("Custom message", "info", "top-left")}>
Custom Toast
</button>
</div>
);
}| Method | Description | Example |
|---|---|---|
toastware.addToast(message, type?, position?, duration?) |
Adds a custom toast with full control | toastware.addToast("Saved!", "success", "top-right") |
toastware.notify(message, type?, position?, duration?) |
Alias for addToast() | toastware.notify("Saved!", "success", "top-right") |
toastware.success(message, position?) |
Shows a success toast | toastware.success("Profile updated!") |
toastware.error(message, position?) |
Shows an error toast | toastware.error("Network error!") |
toastware.warning(message, position?) |
Shows an warning toast | toastware.warning("Warning : message!") |
toastware.info(message, position?) |
Shows an info toast | toastware.info("New update available") |
toastware.removeToastById(id) |
Removes a specific toast by ID | β |
toastware.clearToasts() |
Clears all toasts | toastware.clearToasts() |
toastware.clear() |
Alias for clearToasts() |
toastware.clear() |
Toastware now supports promise-based toast notifications β perfect for async tasks like API calls or file uploads.
toaster.promise(fetch("/api/user"), {
loading: "Fetching user data...",
success: "User loaded successfully!",
error: "Failed to fetch user data.",
});| Key | Type | Description |
|---|---|---|
loading |
string | Message shown while promise is pending |
success |
string | Message shown when promise resolves |
error |
string | Message shown when promise rejects |
import { useToast } from "toastware";
function DemoButton() {
const { addToast } = useToast();
return (
<button
onClick={() =>
addToast({
message: "Hello World!",
type: "success",
position: "top-right",
duration: 3000,
})
}
>
Show Toast
</button>
);
}-
Wraps your app and manages state of all toasts.
-
Props (optional):
defaultPositionβ"top-right" | "top-left" | "bottom-right" | "bottom-left"(default:"top-right")defaultDurationβ number in ms (default:3000)
Hook that gives you access to toast actions.
const { addToast, removeToast, clearToasts } = useToast();-
addToast(options: ToastItem)β Adds a toast.message: stringβ text to showtype: "info" | "success" | "warning" | "error"position?: stringduration?: number(ms)
-
removeToast(id: string | number)β Manually removes a toast. -
clearToasts()β Removes all active toasts.
type ToastItem = {
id?: string | number;
message: string;
type?: "info" | "success" | "warning" | "error";
position?: "top-right" | "top-left" | "bottom-right" | "bottom-left";
duration?: number;
};Default classes provided:
.toast-containerβ wrapper for each position group.toastβ base toast style.toast-contentβ content area.toast-closeβ close button.toast-progressβ progress bar
π You can override or extend styles by importing your own CSS.
- Use
positionto avoid overlapping with app UI. - Keep messages short and clear.
- For error messages, prefer
duration: 5000for better visibility. - Donβt overload user with too many toasts simultaneously.
addToast({
message: "Profile updated successfully!",
type: "success",
position: "bottom-left",
duration: 4000,
});MIT Β© Amresh Maurya