Skip to content

useEscapeKey

A hook for detecting escape key presses.

Installation

Terminal window
npx shadcn add https://darwin-ui.mandalsuraj.com/registry/use-escape-key.json

Usage

import { useEscapeKey } from '@smc/darwin-ui';
export function Modal({ onClose }) {
useEscapeKey(onClose);
return (
<div className="modal">
Press ESC to close
</div>
);
}

API Reference

function useEscapeKey(callback: () => void): void;
ParameterTypeDescription
callback() => voidFunction called on ESC press