A simple React toast notification library with Tailwind CSS
npm install snack-alert> Simple, beautiful toast-style alert system for React. Easy to use. Easy to love.
SnackAlert provides a flexible, lightweight, and customizable way to show toast/snackbar-style notifications in your React app using a modern hook-based API.
``bash`
npm install snackalertor
yarn add snackalert
SnackAlert gives you two powerful ways to get started instantly β automatic injection or app wrapping β with no extra setup.
> Prefer manual control over your root app? Wrap it cleanly with the withSnackAlert helper.
`tsx
// main.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import { App } from './App';
import 'snack-alert/css';
import { withSnackAlert } from 'snack-alert';
const AppWithAlerts = withSnackAlert(App);
ReactDOM.createRoot(document.getElementById('root')!).render(
);
`
> Perfect for static apps, SPAs, or dashboards β SnackAlert mounts itself globally.
`tsx
import 'snack-alert/css';
import { mountSnackAlert } from 'snack-alert';
// Mount the alert system into the DOM (usually called once at app start)
mountSnackAlert();
`
Now you can trigger alerts anywhere using the useAlert hook:
`tsx
import { useAlert, AlertType } from 'snack-alert';
const MyComponent = () => {
const { showAlert } = useAlert();
return (
onClick={() => showAlert({
type: AlertType.INFO,
message: "π₯ͺ SNACK ALERT!!! Have you had a snack today?"
})
}
>
Show Alert
);
};
`
`ts
// snackalert package
export { useAlert } from 'snack-alert';
export { AlertType, mountSnackAlert, withSnackAlert } from 'snack-alert';
`
`tsx
import { useAlert, AlertType } from 'snack-alert';
const MyComponent = () => {
const { showAlert } = useAlert();
const handleClick = () => {
showAlert({
type: AlertType.INFO,
message: "π₯ͺ SNACK ALERT!!! Have you had a snack today?"
});
};
return (
);
};
`
Hook that provides alert functionality in your component.
#### Returns
* showAlert(options: ShowAlertOptions): void
| Option | Type | Required | Description |
| ---------- | ----------- | -------- | ----------------------------------------------------- |
| type | AlertType | β
| Type of alert: INFO, SUCCESS, WARNING, ERROR |message
| | string | β
| Text to display in the alert |duration
| | number | β | Time in milliseconds before dismiss (default: 3000ms) |
`ts`
enum AlertType {
INFO = 'info',
SUCCESS = 'success',
WARNING = 'warning',
ERROR = 'error'
}
`ts`
// index.ts
export { AlertType } from './main.tsx';
export { useAlert } from './core/hooks/provider.ts';
* β‘ One-line usage with useAlert()
* π
Clean, auto-dismiss toasts with type styling
* π Option to customize duration and styles
* π§± Zero dependencies, built with modern React
* π§ͺ Ready for unit & integration testing
* Theming (light/dark/custom)
* Custom icons per alert type
* Toast positioning
* Global config

`tsx`
showAlert({
type: AlertType.SUCCESS,
message: "β
Order placed successfully!",
duration: 5000
});
`bash`
snackalert/
βββ core/
β βββ hooks/
β βββ provider.ts
βββ main.tsx
βββ index.ts
Feel free to open issues or PRs for features, bugs, or enhancements. We'd love your input to make SnackAlert` the best toast solution out there.
MIT License Β© 2025 Emmanuel Bankole
* React Toastify
* Material UI Snackbar
For questions or feedback, reach out via GitHub Issues or email