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] +}