useEscapeKey
Hooks

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.

SignatureTypeScript
function useEscapeKey(enabled: boolean, onEscape: () => void): void;

Usage

ExampleTSX
import { useEscapeKey } from "@solarius/onset";

function Panel({ open, onClose }: { open: boolean; onClose: () => void }) {
  useEscapeKey(open, onClose);
  return open ? <aside>Panel content</aside> : null;
}