Listing 18-6: The Finished Modal Component
import ReactDOM from 'react-dom';
import "./styles.css";
function Modal(props){
return (
{props.isOpen &&
ReactDOM.createPortal((
<div className="modalOverlay">
<div className="modalContainer">
<h1 className="modalTitle">{props.title}</h1>
<div className="modalContent">
{props.children}
</div>
</div>
</div>)
,document.getElementById('modal'))}
)
}
export default Modal;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.