alternative tangled frontend (extremely wip)
at main 16 lines 493 B view raw
1import { useEffect } from "react"; 2import type { Dispatch, SetStateAction } from "react"; 3 4export const useModalEscapeEffect = ({ 5 setShowModal, 6}: { 7 setShowModal: Dispatch<SetStateAction<boolean>>; 8}) => { 9 useEffect(() => { 10 const handler = (e: KeyboardEvent) => { 11 if (e.key === "Escape") setShowModal(false); 12 }; 13 document.addEventListener("keydown", handler); 14 return () => document.removeEventListener("keydown", handler); 15 }, []); 16};