From 85e3d1124f6efd92687dc4eb3c7a29407e600d2b Mon Sep 17 00:00:00 2001 From: mantikoros Date: Thu, 3 Mar 2022 00:01:12 -0500 Subject: [PATCH] use focus hook --- web/hooks/use-focus.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 web/hooks/use-focus.ts diff --git a/web/hooks/use-focus.ts b/web/hooks/use-focus.ts new file mode 100644 index 00000000..a71a0292 --- /dev/null +++ b/web/hooks/use-focus.ts @@ -0,0 +1,11 @@ +import { useRef } from 'react' + +// Focus helper from https://stackoverflow.com/a/54159564/1222351 +export function useFocus(): [React.RefObject, () => void] { + const htmlElRef = useRef(null) + const setFocus = () => { + htmlElRef.current && htmlElRef.current.focus() + } + + return [htmlElRef, setFocus] +}