overleaf/services/web/frontend/js/infrastructure/auto-focus.js
Alf Eaton 2ff1cf43d6 Merge pull request #3470 from overleaf/eslint
Upgrade and configure ESLint

GitOrigin-RevId: ad5aeaf85e72c847a125ff3a9db99a12855e38aa
2020-12-16 03:08:28 +00:00

15 lines
350 B
JavaScript

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