mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
53354224fc
Upgrades biome to 1.6.1, and updates husky pre-commit hook. Most changes here are making type imports explicit.
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { useCallback, useContext } from 'react';
|
|
import UIContext from '../contexts/UIContext';
|
|
import type { IToast } from '../interfaces/toast';
|
|
|
|
const useToast = () => {
|
|
const { setToast } = useContext(UIContext);
|
|
|
|
const hideToast = () =>
|
|
setToast((prev: IToast) => ({
|
|
...prev,
|
|
show: false,
|
|
}));
|
|
|
|
const setToastApiError = useCallback(
|
|
(text: string, overrides?: IToast) => {
|
|
setToast({
|
|
title: 'Something went wrong',
|
|
text,
|
|
type: 'error',
|
|
show: true,
|
|
autoHideDuration: 12000,
|
|
...overrides,
|
|
});
|
|
},
|
|
[setToast],
|
|
);
|
|
|
|
const setToastData = useCallback(
|
|
(toast: IToast) => {
|
|
if (toast.persist) {
|
|
setToast({ ...toast, show: true });
|
|
} else {
|
|
setToast({ autoHideDuration: 6000, ...toast, show: true });
|
|
}
|
|
},
|
|
[setToast],
|
|
);
|
|
|
|
return { setToastData, setToastApiError, hideToast };
|
|
};
|
|
|
|
export default useToast;
|