introduced modal loading spinner.

This commit is contained in:
2025-05-29 22:32:19 +09:00
parent 271e29ee33
commit 5bc9976566
4 changed files with 156 additions and 198 deletions

View File

@@ -0,0 +1,27 @@
import React from 'react';
import ReactDOM from 'react-dom';
import invariant from 'tiny-invariant';
interface DynamicPortalProps {
children: React.ReactNode;
}
const DynamicPortal: React.FC<DynamicPortalProps> = (props) => {
const { children } = props;
const [el] = React.useState(() => document.createElement('div'));
React.useEffect(() => {
const body = document.querySelector('body');
invariant(body, 'The body element is not available. Please ensure this code runs in a browser context.');
if (el.parentNode == null) {
body.appendChild(el);
}
return () => {
if (el.parentNode) {
el.parentNode.removeChild(el);
}
};
}, []);
return ReactDOM.createPortal(children, el);
};
export default DynamicPortal;