import {useEffect, useRef} from "react"; import {type Id, toast} from "react-toastify"; import type {StatusModel} from "../../type/viewModel.ts"; type UseLoadingToastProps = StatusModel & { loadingMessage?: string; } export const useLoadingToast = ({ isLoading, error, loadingMessage = 'Loading ...', successMessage = '완료' }: UseLoadingToastProps) => { const toastId = useRef(null); useEffect(() => { if (isLoading && !toastId.current) { toastId.current = toast.info(loadingMessage); return; } if (!isLoading && toastId.current) { toast.dismiss(toastId.current); toastId.current = null; if (error) { toast.error(error instanceof Error ? error.message : String(error)); } else { toast.success(successMessage); } } }, [isLoading, error, loadingMessage, successMessage]); }