MCPcopy Index your code
hub / github.com/streamich/react-use / useKey

Function useKey

src/useKey.ts:24–41  ·  view source on GitHub ↗
(
  key: KeyFilter,
  fn: Handler = noop,
  opts: UseKeyOptions<T> = {},
  deps: DependencyList = [key]
)

Source from the content-addressed store, hash-verified

22 : () => false;
23
24const useKey = <T extends UseEventTarget>(
25 key: KeyFilter,
26 fn: Handler = noop,
27 opts: UseKeyOptions<T> = {},
28 deps: DependencyList = [key]
29) => {
30 const { event = 'keydown', target, options } = opts;
31 const useMemoHandler = useMemo(() => {
32 const predicate: KeyPredicate = createKeyPredicate(key);
33 const handler: Handler = (handlerEvent) => {
34 if (predicate(handlerEvent)) {
35 return fn(handlerEvent);
36 }
37 };
38 return handler;
39 }, deps);
40 useEvent(event, useMemoHandler, target, options);
41};
42
43export default useKey;

Callers 3

DemoFunction · 0.90
CounterDemoFunction · 0.90
useKeyPressFunction · 0.85

Calls 2

createKeyPredicateFunction · 0.85
useEventFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…