Auth plugins (#155)

This commit is contained in:
Gregory Schier
2025-01-17 05:53:03 -08:00
committed by GitHub
parent e21df98a30
commit bd322162c8
56 changed files with 5468 additions and 1474 deletions

View File

@@ -0,0 +1,18 @@
import { useEffect } from 'react';
export function useKeyboardEvent(
event: 'keyup' | 'keydown',
key: KeyboardEvent['key'],
cb: () => void,
) {
useEffect(() => {
const fn = (e: KeyboardEvent) => {
if (e.key === key) cb();
};
document.addEventListener(event, fn);
return () => document.removeEventListener(event, fn);
// Don't have `cb` as a dep for caller convenience
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [event]);
}