use focus hook
This commit is contained in:
parent
42577b20a9
commit
85e3d1124f
11
web/hooks/use-focus.ts
Normal file
11
web/hooks/use-focus.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { useRef } from 'react'
|
||||||
|
|
||||||
|
// Focus helper from https://stackoverflow.com/a/54159564/1222351
|
||||||
|
export function useFocus(): [React.RefObject<HTMLElement>, () => void] {
|
||||||
|
const htmlElRef = useRef<HTMLElement>(null)
|
||||||
|
const setFocus = () => {
|
||||||
|
htmlElRef.current && htmlElRef.current.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
return [htmlElRef, setFocus]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user