next-toast
v1.0.3
Published
A lightweight toast notification system for Next.js and React.
Maintainers
Readme
NextToast
NextToast is a lightweight, flexible toast notification system for React and Next.js. It is designed to be simple to use, fully customizable, and safe for client components.
It supports standard notifications, loading states, confirmations, promises, and fully custom React components.
Features
- Works with Next.js App Router and React
- Simple global API (
toast.success,toast.error, etc.) - Rich or plain styling modes
- Confirmation toasts with actions
- Promise-based toasts
- Supports ReactNode everywhere (not just strings)
- Configurable close button behavior
- Automatic stacking and dismissal
- Accessible (ARIA roles included)
- No external dependencies
Installation
Copy the source files into your project or install from your package source.
Basic Usage
Mount the toast container once in your app layout:
import { NextToast } from "./next-toast";
export default function RootLayout({ children }) {
return (
<>
{children}
<NextToast />
</>
);
}Trigger a toast from anywhere:
import { toast } from "./toast-store";
toast.success("Saved successfully");
toast.error("Something went wrong");
toast.info("New update available");Toast Types
Supported types:
successerrorinfoloadingdefaultcustom
Rich vs Plain Mode
You can control visual style using the richColors prop.
<NextToast richColors={true} />richColors={false}→ white background, black border, black textrichColors={true}→ semantic colors (success, error, info, loading)
Close Button Control
Global control:
<NextToast position="top-right" richColors={false} closeButton={true} />Per-toast control:
toast.info("Closable toast", { dismissible: true });A toast will show the close button only if:
closeButtonis enabled on<NextToast />dismissibleistruefor that toast
Confirmation Toasts
Confirmation toasts support React components, not just strings.
toast.confirm(
<div>
<strong>Delete item?</strong>
<div>This action cannot be undone.</div>
</div>,
() => {
console.log("Confirmed");
},
{
label: "Delete",
cancelLabel: "Cancel",
dismissible: true,
}
);Confirmation Options
| Option | Type | Description |
| ------------- | --------- | ---------------------- |
| label | ReactNode | Confirm button content |
| cancelLabel | ReactNode | Cancel button content |
| dismissible | boolean | Enables close button |
| duration | number | Auto dismiss time |
Promise Toasts
Handle async flows easily:
toast.promise(
fetch("/api/save"),
{
loading: "Saving...",
success: "Saved",
error: "Failed",
}
);The toast updates automatically based on promise state.
Custom Toasts
Render anything you want:
toast.custom((t) => (
<div>
<h4>Custom Content</h4>
<button onClick={() => toast.dismiss(t.id)}>Close</button>
</div>
));Configuration Props
<NextToast />
| Prop | Type | Default |
| ------------- | ------- | ------------ |
| position | string | top-center |
| richColors | boolean | true |
| closeButton | boolean | true |
| maxVisible | number | 4 |
Accessibility
- Uses proper ARIA roles
- Error toasts use
role="alert" - Screen-reader friendly
- Keyboard accessible close button
File Structure
src/
├─ next-toast.tsx
├─ toast-store.ts
├─ styles.css
index.tsLicense
This project is licensed under the MIT License.
You are free to use, modify, and distribute it.
LICENSE (MIT)
MIT License
Copyright (c) 2026 rimu-7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.