mirror of
https://github.com/IVJAB/adrar.redmush.laravel.git
synced 2026-11-14 17:33:22 +00:00
19 lines
530 B
TypeScript
19 lines
530 B
TypeScript
import { router } from '@inertiajs/react';
|
|
import { useEffect } from 'react';
|
|
import { toast } from 'sonner';
|
|
import type { FlashToast } from '@/types/ui';
|
|
|
|
export function useFlashToast(): void {
|
|
useEffect(() => {
|
|
return router.on('flash', (event) => {
|
|
const flash = (event as CustomEvent).detail?.flash;
|
|
const data = flash?.toast as FlashToast | undefined;
|
|
|
|
if (!data) {
|
|
return;
|
|
}
|
|
|
|
toast[data.type](data.message);
|
|
});
|
|
}, []);
|
|
}
|