Download react-use/src/useKeyPress.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 423 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useKeyPress.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useKeyPress.ts
-
curl -L -o useKeyPress.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useKeyPress.ts
423 Bytes
| import { useState } from 'react'; | |
| import useKey, { KeyFilter } from './useKey'; | |
| const useKeyPress = (keyFilter: KeyFilter) => { | |
| const [state, set] = useState<[boolean, null | KeyboardEvent]>([false, null]); | |
| useKey(keyFilter, (event) => set([true, event]), { event: 'keydown' }, [state]); | |
| useKey(keyFilter, (event) => set([false, event]), { event: 'keyup' }, [state]); | |
| return state; | |
| }; | |
| export default useKeyPress; | |