import Icon from '@/components/Icon'; import { useCallback, useEffect, useState } from 'react'; export function Modal({ children }) { const [isOpen, setIsOpen] = useState(false); const handleEscape = useCallback(e => { if (e.keyCode === 27) { setIsOpen(false); } }, []); useEffect(() => { if (isOpen) { document.addEventListener('keydown', handleEscape, false); } return () => { document.removeEventListener('keydown', handleEscape, false); }; }); const hideModal = e => { setIsOpen(false); }; return isOpen ? (
{children}
) : null; } export default Modal;