init laravel
This commit is contained in:
19
resources/js/hooks/use-flash-toast.ts
Normal file
19
resources/js/hooks/use-flash-toast.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user