1import {GlobalState} from '@/utils/stateMapper'; 2import {useCallback} from 'react'; 3import {IDialogKey, IDialogType} from './components'; 4 5interface IDialogInfo { 6 name: IDialogKey | null; 7 payload: any; 8} 9 10export const dialogInfoStore = new GlobalState<IDialogInfo>({ 11 name: null, 12 payload: null, 13}); 14 15export default function useDialog() { 16 const showDialog = useCallback( 17 <T extends keyof IDialogType>( 18 name: T, 19 payload?: Parameters<IDialogType[T]>[0], 20 ) => { 21 dialogInfoStore.setValue({ 22 name, 23 payload, 24 }); 25 }, 26 [], 27 ); 28 29 const hideDialog = useCallback(() => { 30 dialogInfoStore.setValue({ 31 name: null, 32 payload: null, 33 }); 34 }, []); 35 36 return {showDialog, hideDialog}; 37} 38