Created
May 7, 2020 19:39
-
-
Save baranovxyz/2ad2d7a0f0dce41f202c9d6d74be9feb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => { | |
const [showModal, setShowModal] = useState(false); | |
const handleKeyup = e => e.keyCode === 27 && setShowModal(false); | |
const toggleModal = () => setShowModal(!showModal); | |
useEffect(() => { | |
if (showModal) window.addEventListener('keyup', handleKeyup); | |
return () => window.removeEventListener('keyup', handleKeyup); | |
}); | |
return <div onClick={toggleModal} className="App"> | |
App - click window | |
{showModal && <Modal> | |
<Component /> | |
</Modal>} | |
</div>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment