Introduce Dialog abstraction

Summary: Introduce convenience abstractions to make it easier to manage dialogs imperatively, by promisyfying common dialog abstractions.

Reviewed By: jknoxville, nikoant

Differential Revision: D29790462

fbshipit-source-id: c092c15cf569ec353b9c1042f25cd67e6c76db01
This commit is contained in:
Michel Weststrate
2021-07-22 04:16:01 -07:00
committed by Facebook GitHub Bot
parent 9c4deb3501
commit f74029699f
6 changed files with 179 additions and 48 deletions

View File

@@ -16,13 +16,12 @@ import {render, unmountComponentAtNode} from 'react-dom';
*/
export function renderReactRoot(
handler: (unmount: () => void) => React.ReactElement,
): void {
): () => void {
const div = document.body.appendChild(document.createElement('div'));
render(
handler(() => {
unmountComponentAtNode(div);
div.remove();
}),
div,
);
const unmount = () => {
unmountComponentAtNode(div);
div.remove();
};
render(handler(unmount), div);
return unmount;
}