import { Toast, ToastBody, ToastTitle, Toaster, useId, useToastController, } from "@fluentui/react-components"; import React, { PropsWithChildren } from "react"; type ToastContext = ( title: string, body: string, intent?: "error" | "info" | "success" | "warning" ) => void; const ToastContextK = React.createContext(null); export function ToastProvider(p: PropsWithChildren): React.ReactElement { const toasterId = useId("toaster"); const { dispatchToast } = useToastController(toasterId); const hook: ToastContext = (title, body, intent) => { dispatchToast( {title} {body} , { intent: intent ?? "info" } ); }; return ( <> {p.children} ); } export function useToast(): ToastContext { return React.useContext(ToastContextK)!; }