overleaf/services/web/frontend/js/infrastructure/auto-focus.js

19 lines
374 B
JavaScript
Raw Normal View History

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