react-microtoast
v1.0.0
Published
A lightweight React toast library with progress bar, auto dark mode, and per-toast position control π
Maintainers
Readme
react-microtoast
A lightweight React toast library with progress bar, auto dark mode, and per-toast position control. Micro in size, mighty in features.
Why react-microtoast?
Other toast libraries make you choose β either you get a progress bar, or auto dark mode, or per-toast positions. With react-microtoast you get all three, with a 2-line setup and zero extra config.
| Feature | react-toastify | react-hot-toast | sonner | react-microtoast | |---|---|---|---|---| | Progress bar | β | β | β | β | | Auto dark mode | Manual | Manual | β | β | | Per-toast position | β | β | β | β | | Bundle size | ~50kb | Light | Light | Micro | | Setup | Medium | Easy | Easy | Easiest |
Features
- 4 toast types β success β , error β, warning β οΈ, info βΉοΈ
- Progress bar showing time remaining
- Stack multiple toasts without overlap
- Per-toast position control β each toast can appear in a different corner
- Auto dismiss with configurable duration
- Manual close button
- Auto light & dark mode β no setup needed
- Zero dependencies (only React as peer dep)
- Micro bundle size
Installation
npm install react-microtoastSetup
Just 2 lines β wrap your app with ToastProvider and drop in ToastContainer:
import { ToastProvider, ToastContainer } from 'react-microtoast'
function App() {
return (
<ToastProvider position="top-right" duration={3500}>
<ToastContainer />
<YourApp />
</ToastProvider>
)
}Usage
Use the useToast hook anywhere inside your app:
import { useToast } from 'react-microtoast'
function MyComponent() {
const toast = useToast()
return (
<div>
<button onClick={() => toast.success('Profile saved!')}>Save</button>
<button onClick={() => toast.error('Something went wrong!')}>Delete</button>
<button onClick={() => toast.warning('Please review before continuing.')}>Submit</button>
<button onClick={() => toast.info('New update available.')}>Info</button>
</div>
)
}Per-toast Options
Override position and duration individually per toast:
toast.success('Done!', { position: 'bottom-left' })
toast.error('Failed!', { duration: 8000 })
toast.info('Heads up!', { duration: 5000, position: 'top-left' })ToastProvider Props
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| position | string | "top-right" | Default position for all toasts |
| duration | number | 3500 | Auto dismiss time in milliseconds |
Position options: top-right top-left bottom-right bottom-left
Toast Methods
| Method | Description |
|--------|-------------|
| toast.success(message, options?) | Green success toast |
| toast.error(message, options?) | Red error toast |
| toast.warning(message, options?) | Amber warning toast |
| toast.info(message, options?) | Blue info toast |
Dark Mode
Fully automatic β uses prefers-color-scheme under the hood. No class toggling, no extra props, no setup.
Project Structure
react-microtoast/
βββ src/
β βββ components/
β β βββ Toast.jsx
β β βββ ToastContainer.jsx
β βββ context/
β β βββ ToastContext.jsx
β βββ hooks/
β β βββ useToast.js
β βββ styles/
β β βββ toast.css
β βββ index.js
βββ package.json
βββ README.mdLicense
MIT β free to use in any project.
Made for devs who just want toasts to work. Micro in size, mighty in features.
