import * as React from 'react'; import { ToastView } from './ToastView'; import type { ToastViewRef, ToastViewType } from './types'; /** * Context of the ToastView. */ export const ToastViewContext = React.createContext( undefined ); ToastViewContext.displayName = 'UIKitToastViewContext'; /** * Properties of the ToastView context. */ type ToastViewContextProps = React.PropsWithChildren<{}>; /** * The ToastView context's provider. */ export function ToastViewContextProvider(props: ToastViewContextProps) { const { children } = props; const ref = React.useRef({} as any); const getToastViewRef = () => ref.current; return ( {children} ); } /** * Get the ToastView context's value. * @returns The ToastView context's value. */ export function useToastViewContext(): ToastViewType { const toast = React.useContext(ToastViewContext); if (!toast) throw Error(`${ToastViewContext.displayName} is not provided`); return toast; }