The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/views/hooks/useImperativeModal.ts

23 lines
625 B

import type { Dispatch, SetStateAction, ReactNode } from 'react';
import { createElement, useEffect } from 'react';
import { imperativeModal } from '../../lib/imperativeModal';
export const useImperativeModal = (setModal: Dispatch<SetStateAction<ReactNode>>): void => {
useEffect(() => {
const unsub = imperativeModal.on('update', (descriptor) => {
if (descriptor === null) {
return setModal(null);
}
if ('component' in descriptor) {
setModal(
createElement(descriptor.component, {
key: Math.random(),
...descriptor.props,
}),
);
}
});
return unsub;
}, [setModal]);
};