MCPcopy Create free account
hub / github.com/streamich/react-use / useKeyPressEvent

Function useKeyPressEvent

src/useKeyPressEvent.ts:5–19  ·  view source on GitHub ↗
(
  key: string | KeyFilter,
  keydown?: Handler | null | undefined,
  keyup?: Handler | null | undefined,
  useKeyPress = useKeyPressDefault
)

Source from the content-addressed store, hash-verified

3import useUpdateEffect from './useUpdateEffect';
4
5const useKeyPressEvent = (
6 key: string | KeyFilter,
7 keydown?: Handler | null | undefined,
8 keyup?: Handler | null | undefined,
9 useKeyPress = useKeyPressDefault
10) => {
11 const [pressed, event] = useKeyPress(key);
12 useUpdateEffect(() => {
13 if (!pressed && keyup) {
14 keyup(event!);
15 } else if (pressed && keydown) {
16 keydown(event!);
17 }
18 }, [pressed]);
19};
20
21export default useKeyPressEvent;

Callers 2

DemoFunction · 0.90
DemoKeyboardJsFunction · 0.90

Calls 3

useKeyPressFunction · 0.85
useUpdateEffectFunction · 0.85
keydownFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…