1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/frontend/src/hooks/useToast.tsx
Fredrik Strand Oseberg ded3c22bb1 Feat/new addons table (#1021)
* feat: initial list of available addons

* feat: add columns

* fix: update referential equality

* fix: remove search

* fix: remove unused imports

* fix: padding

* fix: imports

* refactor: based on comments
2022-05-25 15:37:32 +02:00

43 lines
1.1 KiB
TypeScript

import { useCallback, useContext } from 'react';
import UIContext from '../contexts/UIContext';
import { IToast } from '../interfaces/toast';
const useToast = () => {
const { setToast } = useContext(UIContext);
const hideToast = () =>
setToast((prev: IToast) => ({
...prev,
show: false,
}));
const setToastApiError = useCallback(
(errorText: string, overrides?: IToast) => {
setToast({
title: 'Something went wrong',
text: `We had trouble talking to our API. Here's why: ${errorText}`,
type: 'error',
show: true,
autoHideDuration: 12000,
...overrides,
});
},
[setToast]
);
const setToastData = useCallback(
(toast: IToast) => {
if (toast.persist) {
setToast({ ...toast, show: true });
} else {
setToast({ ...toast, show: true, autoHideDuration: 6000 });
}
},
[setToast]
);
return { setToastData, setToastApiError, hideToast };
};
export default useToast;