Notification toast avec animation de disparition automatique, positionnée en bas à droite.
Notification inline simple avec disparition automatique après 5 secondes.
Hook personnalisé pour gérer les notifications avec animation.
Hook personnalisé pour gérer les notifications simples.
import React from "react";
import useNotification from "../hooks/useNotification";
import Notification from "../components/Notification";
function Home() {
const { notification, showNotification, hideNotification } = useNotification();
// Utilisation
const handleSomeAction = () => {
// Pour une notification de succès
showNotification("Action réussie !", "success");
// Pour une notification d'erreur
showNotification("Erreur lors de l'action", "error");
};
return (
<div>
{/* Votre contenu */}
{/* Notification Toast */}
<Notification
notification={notification}
onClose={hideNotification}
/>
</div>
);
}import React from "react";
import useSimpleNotification from "../hooks/useSimpleNotification";
import SimpleNotification from "../components/SimpleNotification";
function Admin() {
const { notification, showNotification, hideNotification } = useSimpleNotification();
// Utilisation
const handleSomeAction = () => {
// Pour une notification de succès
showNotification("Action réussie !", "success");
// Pour une notification d'erreur
showNotification("Erreur lors de l'action", "error");
};
return (
<div>
{/* Notifications */}
<SimpleNotification notification={notification} />
{/* Votre contenu */}
</div>
);
}- Réutilisabilité : Les composants peuvent être utilisés dans n'importe quelle page
- Consistance : Même comportement dans toute l'application
- Maintenabilité : Code centralisé, plus facile à modifier
- Personnalisation : Facilement extensible pour ajouter de nouveaux types
- Clean Code : Sépare la logique de notification du reste du composant
"success": Notification verte (par défaut)"error": Notification rouge
Pour ajouter de nouveaux types de notifications, modifiez les composants et ajoutez les styles CSS correspondants.