mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	* 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
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			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;
 |