overleaf/services/web/frontend/js/infrastructure/auto-focus.js
Timothée Alby 420aa4a657 Merge pull request #3232 from overleaf/ta-file-tree-react
React File Tree

GitOrigin-RevId: fb3141ba8cd9ca0d68e87edb74764a360144c8fe
2020-11-27 03:05:05 +00:00

18 lines
374 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 }
}