import {useEffect, useRef} from "react"; import {type Id, toast} from "react-toastify"; type UseLoadingToastProps = { isLoading: boolean; error?: Error | null; loadingMessage?: string; successMessage?: 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.message); } else { toast.success(successMessage); } } }, [isLoading, error, loadingMessage, successMessage]); }