use-initial-focus
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

use-initial-focus

NPM version NPM yearly download

React hook for auto focus on an element after rendering.
Usually, If we just want to focus on an element when it mounts (initially renders) a simple use of the autoFocus attribute will do.
But in the nested components we are difficult to handle initial focus element, for examples: Modal, Popover

Installation

yarn add use-initial-focus

Usage

Example: https://codesandbox.io/s/use-initial-focus-example-c8eyq

import {useFocus} from 'use-initial-focus';

const MyComponent = () => {
  const initialFocus = useFocus();

  return <button ref={ref}>My Button</button>;
};

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i use-initial-focus

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

3.17 kB

Total Files

7

Last publish

Collaborators

  • nghiepit