pleroma/app/soapbox/components/ui/portal/portal.tsx

31 lines
538 B
TypeScript
Raw Normal View History

2023-02-10 11:43:41 -08:00
import React, { useLayoutEffect, useState } from 'react';
import ReactDOM from 'react-dom';
interface IPortal {
children: React.ReactNode
}
/**
* Portal
*/
2023-02-10 10:49:59 -08:00
const Portal: React.FC<IPortal> = ({ children }) => {
2023-02-10 11:43:41 -08:00
const [isRendered, setIsRendered] = useState<boolean>(false);
2023-02-10 10:49:59 -08:00
useLayoutEffect(() => {
2023-02-10 11:43:41 -08:00
setIsRendered(true);
}, []);
2023-02-10 10:49:59 -08:00
2023-02-10 11:43:41 -08:00
if (!isRendered) {
2023-02-10 10:49:59 -08:00
return null;
}
return (
ReactDOM.createPortal(
children,
document.getElementById('soapbox') as HTMLDivElement,
)
);
};
export default Portal;