Skip to content

Instantly share code, notes, and snippets.

@SafaElmali
Created September 18, 2021 15:30
Show Gist options
  • Save SafaElmali/8689b28bdf36887364d203c973f99c3f to your computer and use it in GitHub Desktop.
Save SafaElmali/8689b28bdf36887364d203c973f99c3f to your computer and use it in GitHub Desktop.
import "../styles/modal.css";
import { createPortal } from "react-dom";
const ModalWithPortal = ({
isOpenPortal,
setIsOpenPortal,
productName = "",
}) => {
if (!isOpenPortal) return null;
return createPortal(
<div className="modal-container">
<div className="modal-header">
<h1>{productName}</h1>
</div>
<button onClick={() => setIsOpenPortal(false)}>Close modal</button>
</div>,
document.getElementById("basket-item")
);
};
export default ModalWithPortal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment