
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@metadiv-studio/alert
Advanced tools
A modern, theme-aware React alert/toast notification system built on top of Sonner. This package provides a clean API for displaying various types of notifications with support for actions, descriptions, and internationalization through React Context.
npm i @metadiv-studio/alert
This package requires the following peer dependencies:
Important: You must wrap your application with the AlertProvider component to enable the alert context throughout your app.
import { AlertProvider } from '@metadiv-studio/alert';
function App() {
return (
<AlertProvider>
{/* Your app content goes here */}
<div>Your app content</div>
</AlertProvider>
);
}
import { useAlertContext } from '@metadiv-studio/alert';
function MyComponent() {
const { success, error, info, notify } = useAlertContext();
const handleSuccess = () => {
success('Operation completed successfully!');
};
const handleError = () => {
error('Something went wrong!');
};
const handleInfo = () => {
info('New update available!');
};
const handleNotify = () => {
notify('You have a new message!');
};
return (
<div>
<button onClick={handleSuccess}>Show Success</button>
<button onClick={handleError}>Show Error</button>
<button onClick={handleInfo}>Show Info</button>
<button onClick={handleNotify}>Show Notify</button>
</div>
);
}
import { useAlertContext } from '@metadiv-studio/alert';
function MyComponent() {
const { success, error, info, notify } = useAlertContext();
// Success alert
success('File uploaded successfully!');
// Error alert
error('Upload failed!');
// Info alert
info('System maintenance scheduled');
// General notification
notify('New message received');
}
function MyComponent() {
const { success, error, info, notify } = useAlertContext();
// Success with description
success('File uploaded!', 'Your file has been successfully uploaded to the cloud.');
// Error with description
error('Upload failed!', 'The file size exceeds the maximum limit of 10MB.');
// Info with description
info('Maintenance scheduled!', 'System will be unavailable from 2-4 AM tomorrow.');
// Notify with description
notify('Backup completed!', 'Your data has been backed up successfully.');
}
function MyComponent() {
const { success, error, info, notify } = useAlertContext();
// Success with action button
success('Action completed successfully!', 'Click to view details', {
label: 'View Details',
onClick: () => {
console.log('View details clicked!');
// Navigate to details page or perform action
}
});
// Error with retry action
error('Something went wrong!', 'Click to retry the operation', {
label: 'Retry',
onClick: () => {
console.log('Retry clicked!');
// Retry the failed operation
}
});
// Info with download action
info('New update available!', 'Click to download now', {
label: 'Download',
onClick: () => {
console.log('Download clicked!');
// Trigger download
}
});
}
function MyComponent() {
const { successSave, successDelete } = useAlertContext();
// Success save message (with internationalization)
const handleSave = async () => {
await successSave();
};
// Success save with custom action
const handleSaveWithAction = async () => {
await successSave({
label: 'View Changes',
onClick: () => navigate('/changes')
});
};
// Success delete message
const handleDelete = async () => {
await successDelete();
};
// Success delete with undo action
const handleDeleteWithUndo = async () => {
await successDelete({
label: 'Undo',
onClick: () => undoDelete()
});
};
}
The package supports internationalization through @metadiv-studio/translation. For the predefined success messages (successSave and successDelete), the locale is automatically detected from the translation context.
import { TranslationProvider } from '@metadiv-studio/translation';
function App() {
return (
<TranslationProvider>
<AlertProvider>
{/* Your app content */}
</AlertProvider>
</TranslationProvider>
);
}
The alert system automatically detects and applies your application's theme using next-themes. It supports:
import { ThemeProvider } from 'next-themes';
import { AlertProvider } from '@metadiv-studio/alert';
function App() {
return (
<ThemeProvider>
<AlertProvider>
{/* Your app content */}
</AlertProvider>
</ThemeProvider>
);
}
notify which appears in top-center)function MyComponent() {
const { success, info, notify } = useAlertContext();
const triggerMultipleAlerts = () => {
// Trigger multiple alerts in sequence
success('First alert!');
setTimeout(() => info('Second alert!'), 500);
setTimeout(() => notify('Third alert!'), 1000);
};
const triggerAllTypes = () => {
// Trigger all types at once
success('Success alert!');
error('Error alert!');
info('Info alert!');
notify('Notify alert!');
};
}
function MyComponent() {
const { info, notify } = useAlertContext();
const showLongMessage = () => {
info('This is a very long message that demonstrates how the alert system handles extended text content.');
};
const showHtmlContent = () => {
info('Form validation error',
<span>Please check the following fields: <strong>Email</strong> and <em>Password</em></span>
);
};
const showEmojis = () => {
notify('Emojis work! 🎉 🚀 ✨ 🎯 💡');
};
}
function MyComponent() {
const { success, info } = useAlertContext();
const handleActionWithNavigation = () => {
success('Action completed!', 'Click to view details', {
label: 'View Details',
onClick: () => {
// Navigate to details
navigate('/details');
// Show another alert
info('Navigating to details page...');
}
});
};
}
@metadiv-studio/alert/
├── AlertProvider # React context provider for alerts
├── useAlertContext # React hook to access alert functions
└── Context Methods:
├── success() # Success notifications
├── error() # Error notifications
├── info() # Information notifications
├── notify() # General notifications
├── successSave() # Predefined save success
└── successDelete() # Predefined delete success
<AlertProvider>useAlertContext() hook in components to access alert functionsAlertProvider is wrapped in your theme providerTranslationProvider for i18n support<AlertProvider>useAlertContext() hook correctlyThemeProvider from next-themesAlertProvider is inside the theme contextTranslationProvider from @metadiv-studio/translationuseAlertContext() is called inside a component that's wrapped by AlertProviderSee the testing page for comprehensive examples of all alert types and configurations.
This package is part of the Metadiv Studio ecosystem. For issues, feature requests, or contributions, please refer to the project repository.
MIT License - see LICENSE file for details.
FAQs
A minimal, theme-agnostic React alert component
We found that @metadiv-studio/alert demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.