@lad-tech/mobydick-core
Version:
React Native components library focused on usability, accessibility and developer experience
31 lines (26 loc) • 711 B
text/typescript
import {FC, useRef} from 'react';
import {IContentProps, IPopup} from '../types';
import {MobyDickPopup} from '../MobyDickPopup';
const usePopup = <P>(modal: FC<P & IContentProps>) => {
const id = useRef<string | null>(null);
return {
open: (props?: IPopup<P>['props']) => {
id.current = MobyDickPopup.openPopup({
Content: modal,
props:
props ||
({} as Omit<P, keyof IContentProps> & Partial<IContentProps>),
});
},
close: () => {
if (id.current) {
MobyDickPopup.closePopup(id.current);
id.current = null;
}
},
closeAll: () => {
MobyDickPopup.closeAllPopups();
},
};
};
export default usePopup;