-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* React cleanup (#82607) ## About The Pull Request - No defaultHooks in react. Might fix issues where pages were not scrollable on hover. - createRef in a functional component. should be useref ## Why It's Good For The Game Code improvement * React cleanup --------- Co-authored-by: Jeremiah <[email protected]>
- Loading branch information
1 parent
d4a333c
commit d710d3e
Showing
3 changed files
with
28 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import { createRef, PropsWithChildren, useEffect } from 'react'; | ||
import { PropsWithChildren, useEffect, useRef } from 'react'; | ||
|
||
export const Autofocus = (props: PropsWithChildren) => { | ||
const ref = createRef<HTMLDivElement>(); | ||
/** Used to force the window to steal focus on load. Children optional */ | ||
export function Autofocus(props: PropsWithChildren) { | ||
const { children } = props; | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
const timer = setTimeout(() => { | ||
ref.current?.focus(); | ||
}, 1); | ||
|
||
return () => { | ||
clearTimeout(timer); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div ref={ref} tabIndex={-1}> | ||
{props.children} | ||
{children} | ||
</div> | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters