mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 11:11:58 -05:00
19 lines
374 B
JavaScript
19 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 }
|
||
|
}
|