@nath-green/hooks

0.0.3 • Public • Published

hooks

Collection of hooks

useFocus

Returns ref and setFocus() to be used on an element which will receive event based focus.

import { useFocus } from '@nath-green/hooks';

const { ref, setFocus } = useFocus();

<button onClick={() => setFocus()}>Focus heading</button>
<h1 ref={ref} tabIndex="-1">Focus on me</h1>

Use case

When a modal has opened and the focus should be set to the close button.

useFocusOnMount

Returns a ref to be used on an element which will receive focus on mount.

import { useFocusOnMount } from '@nath-green/hooks';

const focusRef = useFocusOnMount();

<button ref={focusRef}>Focused</button>

Use case

When a modal has opened and the focus should be set to the close button.

Readme

Keywords

none

Package Sidebar

Install

npm i @nath-green/hooks

Weekly Downloads

0

Version

0.0.3

License

none

Unpacked Size

3.24 kB

Total Files

4

Last publish

Collaborators

  • nath-green