utoaster
v1.0.3
Published
Ultra-light 3KB toast/notification system for React + TS
Maintainers
Readme
UToaster
Ultra-light 3KB toast/notification system for React + TypeScript
A minimal, fast, and easy-to-use toast library for React projects. Works without any UI framework. Tailwind CSS optional.
Features
- Tiny: ~3KB
- Simple API:
useToast()hook andtoastglobal helper - React + TypeScript support
- Optional Tailwind integration
- Auto-dismiss toasts
- Accessible (
aria-livepolite)
Installation
npm install utoaster
# or
yarn add utoasterPeer dependency: React >= 18
Usage
1. Wrap your app with the provider
import React from 'react';
import { ToastProvider } from 'utoaster';
import App from './App';
export default function Root() {
return (
<ToastProvider>
<App />
</ToastProvider>
);
}2. Using the useToast hook
import { useToast } from 'utoaster';
function MyComponent() {
const { success, error, info, warn } = useToast();
return (
<div>
<button onClick={() => success('Saved successfully!')}>Save</button>
<button onClick={() => error('Something went wrong!')}>Fail</button>
</div>
);
}3. Using the global toast helper (imperative)
import { toast } from 'utoaster';
toast.success('Operation completed');
toast.error('Failed to save');Note: The global
toastworks anywhere after theToastProvideris mounted.
Props & Options
Toast options
type:'info' | 'success' | 'error' | 'warn'(default'info')message:string(required)title:string(optional)duration:numberin milliseconds (optional, default 4000)
useToast() API
show(toastOptions)→ returns toast idsuccess(message, title?, duration?)error(message, title?, duration?)info(message, title?, duration?)warn(message, title?, duration?)
Global toast API
toast.show(toastOptions)→ returns toast idtoast.success(...),toast.error(...), etc.
Styling
- Inline styles included by default for minimal size.
- Tailwind optional: replace inline styles with Tailwind classes if desired.
- Toasts appear at bottom-right by default.
TypeScript
- Fully typed.
ToastProvider,useToast, andtoastall have proper types.
License
MIT
