Listing 18-5: The App Component
import {useState} from 'react';
import Modal from './Modal';
import './styles.css';
function App() {
const[isModalOpen,setModalOpen] = useState(false);
const toggleModal = () => setModalOpen(!isModalOpen);
return (
<div>
<button onClick={toggleModal}>Open the Modal</button>
<Modal title="Warning" isOpen={isModalOpen}>
<p>This Modal is awesome.</p>
<button onClick={toggleModal}>close modal</button>
</Modal>
</div>
);
}
export default App;
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.