overleaf/services/web/frontend/js/shared/hooks/use-ref-with-auto-focus.js

18 lines
373 B
JavaScript
Raw Normal View History

import { useRef, useEffect } from 'react'
export function useRefWithAutoFocus() {
const autoFocusedRef = useRef()
useEffect(() => {
if (autoFocusedRef.current) {
window.requestAnimationFrame(() => {
if (autoFocusedRef.current) {
autoFocusedRef.current.focus()
}
})
}
}, [autoFocusedRef])
return { autoFocusedRef }
}