A lightweight, zero-dependency React notification/alert library with a simple API. Display success, error, and warning alerts that automatically appear at the top-right of your screen and dismiss after 2 seconds.
- Simple API:
alert.success(),alert.error(),alert.warning() - Auto-dismiss: Alerts automatically disappear after 2 seconds
- Instant appearance: Alerts appear immediately with optimized timing
- Global alerts: Works anywhere in your app after setup
- Lightweight: No external dependencies (only React)
- TypeScript support: Includes TypeScript definitions
- Clean design: Modern, minimal UI with smooth slide-in/out animations
- Easy integration: Just add one component to your root
- FIFO removal: Alerts remove one by one in first-in-first-out order
Install the package using npm or yarn:
npm install react-alertify-minior
yarn add react-alertify-miniImport and add the AlertContainer component once at the root of your React application.
For React 18+ (using createRoot):
// index.js or main.jsx
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import { AlertContainer } from "react-alertify-mini";
ReactDOM.createRoot(document.getElementById("root")).render(
<>
<AlertContainer />
<App />
</>
);For React 17 (using render):
// index.js
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { AlertContainer } from "react-alertify-mini";
ReactDOM.render(
<>
<AlertContainer />
<App />
</>,
document.getElementById("root")
);Import the alert object and call its methods from any component:
import { alert } from "react-alertify-mini";
function MyComponent() {
const handleSave = () => {
// Your save logic here
alert.success("Data saved successfully!");
};
const handleError = () => {
alert.error("Something went wrong!");
};
const handleWarning = () => {
alert.warning("Please check your input!");
};
return (
<div>
<button onClick={handleSave}>Save</button>
<button onClick={handleError}>Show Error</button>
<button onClick={handleWarning}>Show Warning</button>
</div>
);
}import { alert } from "react-alertify-mini";
function App() {
return (
<div>
<button onClick={() => alert.success("Operation completed!")}>
Success
</button>
<button onClick={() => alert.error("Failed to process request")}>
Error
</button>
<button onClick={() => alert.warning("Please review your data")}>
Warning
</button>
</div>
);
}import { alert } from "react-alertify-mini";
async function fetchData() {
try {
const response = await fetch("/api/data");
const data = await response.json();
alert.success("Data loaded successfully!");
return data;
} catch (error) {
alert.error("Failed to load data");
console.error(error);
}
}import { alert } from "react-alertify-mini";
function LoginForm() {
const handleSubmit = (e) => {
e.preventDefault();
const email = e.target.email.value;
const password = e.target.password.value;
if (!email || !password) {
alert.warning("Please fill in all fields");
return;
}
// Login logic
alert.success("Login successful!");
};
return <form onSubmit={handleSubmit}>...</form>;
}Displays a green success alert.
alert.success("Operation completed successfully!");Displays a red error alert.
alert.error("An error occurred!");Displays an orange/yellow warning alert.
alert.warning("Please check your input!");React component that renders the alert container. Must be added once at the root of your application.
import { AlertContainer } from "react-alertify-mini";
// Add to your root component
<AlertContainer />- Position: Top-right corner of the screen
- Auto-dismiss: 2 seconds after appearing (configurable)
- Progress bar: Visual countdown bar at the bottom of each alert
- Animations: Smooth slide-in from right and fade-out transitions
- Colors:
- ✅ Success: Green (
#4caf50) - ❌ Error: Red (
#f44336) ⚠️ Warning: Orange (#ff9800)
- ✅ Success: Green (
- Styling: White text, rounded corners, subtle shadow
- Stacking: Multiple alerts stack vertically with spacing
- Removal: Alerts remove independently in FIFO (first-in-first-out) order
src/
├── AlertContainer.jsx # React component for rendering alerts
├── alertStore.js # Alert state management
├── index.js # Main entry point (exports)
└── index.d.ts # TypeScript definitions
This package includes TypeScript definitions. If you're using TypeScript, you'll get full type support:
import { alert, AlertContainer } from "react-alertify-mini";
// TypeScript will provide autocomplete and type checking
alert.success("Typed message"); // ✅
alert.error(123); // ❌ Type error: expects string- React: >= 17.0.0
- React DOM: >= 17.0.0
These are peer dependencies, so make sure you have them installed in your project.
Contributions are welcome! If you'd like to contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/feature branch name) - Open a Pull Request
MIT License © 2025 Sapnendra Jaiswal
- Repository: https://github.com/sapnendra/react-alertify-mini
- Issues: https://github.com/sapnendra/react-alertify/issues
- NPM Package: react-alertify-mini
- Only add
<AlertContainer />once at your app root - Alerts automatically stack if multiple are triggered quickly
- Each alert has a unique ID and manages its own lifecycle independently
- The progress bar provides visual feedback on remaining time
- Alerts appear instantly when triggered for optimal user experience
- The alert container is positioned with
z-index: 9999to appear above most content - Alerts remove themselves one by one in the order they were created (FIFO)
Made with ❤️ by Sapnendra Jaiswal