Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 1x | import React, { useEffect, useState } from "react";
import { createPortal } from "react-dom";
import styles from "./Modal.module.scss";
const Modal = ({ children, isOpen }: { children: React.ReactNode, isOpen: boolean }) => {
const [attach, setAttach] = useState(false);
useEffect(() => {
setAttach(true);
return () => setAttach(false);
}, []);
if (!isOpen || !attach) return null;
return createPortal(
<article className={styles.overlay}>
<section className={styles.container} tabIndex={-1} aria-labelledby="ProfileModalLabel">
{children}
</section>
</article>,
document.querySelector("#modal-root")!
);
};
export default Modal;
|