Create toast provider

This commit is contained in:
Takeshi Kimata
2024-05-27 23:15:30 +09:00
parent 5ae4417c23
commit cfd6a9b339
10 changed files with 132 additions and 31 deletions

View File

@@ -0,0 +1,31 @@
import { createContext } from 'react';
import { ToastContextType, ToastProps } from '@/types/toast';
// TODO Temporary use until NextUI's Toast is released.
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
const defaultContext = {
showToast: (text: string, mode: string) => {},
};
const ToastContext = createContext<ToastContextType>(defaultContext);
const ToastProvider = ({ children }: ToastProps) => {
const showToast = (text: string, mode: string) => {
toast(text, { theme: 'light' });
};
const toastContext = {
showToast,
};
return (
<ToastContext.Provider value={toastContext}>
<ToastContainer hideProgressBar={true} />
{children}
</ToastContext.Provider>
);
};
export { ToastContext };
export default ToastProvider;