Last active
April 27, 2019 23:57
-
-
Save timc1/5401146d8a7cb26c67addc4a5ca657d7 to your computer and use it in GitHub Desktop.
Simple hook to control of the flow of focus.
This file contains hidden or 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
| import React from "react" | |
| export default function useFocus() { | |
| const cachedElement = React.useRef(null) | |
| const setFocusCache = () => (cachedElement.current = document.activeElement) | |
| const setFocus = () => | |
| cachedElement.current ? cachedElement.current.focus() : {} | |
| return { setFocusCache, setFocus } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage