import React from "react" ; import { uniqKey } from "../utils/uniqKey" ; import { createPortalDOM , PortalDOM } from "../utils/dom" ; import { Toast as ToastComponent , ToastProps } from "./Toast" ; param option export function showToast ( option ) { const { mount , destroy } = createPortalDOM ( ) ; let props = { } ; if ( React . isValidElement ( option ) || typeof option !== "object" ) { props . content = option ; } else { props = option as ToastProps ; } props . onHide = destroy ; mount ( < ToastComponent { ... props } / > ) ; } param option let portalDOM = null ; export function showUniqToast ( option ) { if ( ! portalDOM ) { portalDOM = createPortalDOM ( ) ; } let props = { } ; if ( React . isValidElement ( option ) || typeof option !== "object" ) { props . content = option ; } else { props = option as ToastProps ; } const onHide = ( ) => { portalDOM ?. destroy ( ) ; portalDOM = null ; } ; props . onHide = onHide ; portalDOM . mount ( < ToastComponent { ... props } key = { uniqKey ( ) } / > ) ; }