useEscapeKey
Run a callback when Escape is pressed while the listener is enabled.
Signature
Attaches a single keydown listener while enabled is true. enabled comes first in the argument order.
function useEscapeKey(enabled: boolean, onEscape: () => void): void;Usage
import { useEscapeKey } from "@solarius/onset";
function Panel({ open, onClose }: { open: boolean; onClose: () => void }) {
useEscapeKey(open, onClose);
return open ? <aside>Panel content</aside> : null;
}