Download react-use/src/useKeyPressEvent.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 560 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useKeyPressEvent.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useKeyPressEvent.ts
-
curl -L -o useKeyPressEvent.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useKeyPressEvent.ts
560 Bytes
| import { Handler, KeyFilter } from './useKey'; | |
| import useKeyPressDefault from './useKeyPress'; | |
| import useUpdateEffect from './useUpdateEffect'; | |
| const useKeyPressEvent = ( | |
| key: string | KeyFilter, | |
| keydown?: Handler | null | undefined, | |
| keyup?: Handler | null | undefined, | |
| useKeyPress = useKeyPressDefault | |
| ) => { | |
| const [pressed, event] = useKeyPress(key); | |
| useUpdateEffect(() => { | |
| if (!pressed && keyup) { | |
| keyup(event!); | |
| } else if (pressed && keydown) { | |
| keydown(event!); | |
| } | |
| }, [pressed]); | |
| }; | |
| export default useKeyPressEvent; | |