Fix focus input bug

This commit is contained in:
James Grugett 2022-07-09 16:35:43 -05:00
parent 376feca7dc
commit 7270c66a91

View File

@ -1,11 +1,12 @@
import { useRef } from 'react' import { useRef } from 'react'
import { useEvent } from './use-event'
// Focus helper from https://stackoverflow.com/a/54159564/1222351 // Focus helper from https://stackoverflow.com/a/54159564/1222351
export function useFocus(): [React.RefObject<HTMLElement>, () => void] { export function useFocus(): [React.RefObject<HTMLElement>, () => void] {
const htmlElRef = useRef<HTMLElement>(null) const htmlElRef = useRef<HTMLElement>(null)
const setFocus = () => { const setFocus = useEvent(() => {
htmlElRef.current && htmlElRef.current.focus() htmlElRef.current && htmlElRef.current.focus()
} })
return [htmlElRef, setFocus] return [htmlElRef, setFocus]
} }