allow typing phone number with desktop keyboard

This commit is contained in:
m5r
2021-09-01 06:42:39 +08:00
parent b4f06e5471
commit 98485bd034
2 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,17 @@
import { useCallback, useEffect } from "react";
export default function useKeyPress(onKeyPress: (key: string) => void) {
const onKeyDown = useCallback(
({ key }: KeyboardEvent) => {
onKeyPress(key);
},
[onKeyPress],
);
useEffect(() => {
window.addEventListener("keydown", onKeyDown);
return () => {
window.removeEventListener("keydown", onKeyDown);
};
}, [onKeyDown]);
}