Files
cinny/src/app/hooks/useKeyDown.ts
T

11 lines
304 B
TypeScript
Raw Normal View History

2023-06-12 21:15:23 +10:00
import { useEffect } from 'react';
export const useKeyDown = (target: Window, callback: (evt: KeyboardEvent) => void) => {
useEffect(() => {
target.addEventListener('keydown', callback);
return () => {
target.removeEventListener('keydown', callback);
};
}, [target, callback]);
};