1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-04 01:18:20 +02:00
unleash.unleash/frontend/src/hooks/useToast.tsx
2021-09-30 10:24:16 +02:00

33 lines
730 B
TypeScript

import { useState } from 'react';
import Toast from '../component/common/Toast/Toast';
export interface IToast {
show: boolean;
type: 'success' | 'info' | 'warning' | 'error';
text: string;
}
const useToast = () => {
const [toastData, setToastData] = useState<IToast>({
show: false,
type: 'success',
text: '',
});
const hideToast = () => {
setToastData((prev: IToast) => ({ ...prev, show: false }));
};
const toast = (
<Toast
show={toastData.show}
onClose={hideToast}
text={toastData.text}
type={toastData.type}
/>
);
return { toast, setToastData, hideToast };
};
export default useToast;