Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useFocus() hook to react-router-dom #6454

Closed
wants to merge 1 commit into from
Closed

Add useFocus() hook to react-router-dom #6454

wants to merge 1 commit into from

Conversation

pshrmn
Copy link
Contributor

@pshrmn pshrmn commented Nov 4, 2018

Like #6449, but as a hook.

import { useFocus } from "react-router-dom";

function App() {
  const ref = useFocus();
  return (
    <main tabIndex={-1} ref={ref}>
      {/* ... */}
    </main>
  );
}

I was having timing issues in the tests and had to use useLayoutEffect in order to get them passing.

@pshrmn
Copy link
Contributor Author

pshrmn commented Nov 22, 2018

In the React Hooks RFC, it was mentioned that there will probably be a native useFocus hook at some point, so it wouldn't hurt to rename this to prevent any future accidental collisions. useNavigationFocus? useRouterFocus?

I'm not exactly sure what the use case for React.useFocus is, but I don't think that it will make this unnecessary.

@pshrmn pshrmn closed this Jul 3, 2019
@pshrmn pshrmn deleted the use-focus branch July 3, 2019 14:27
@mjackson mjackson mentioned this pull request Aug 26, 2019
23 tasks
@lock lock bot locked as resolved and limited conversation to collaborators Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant