https://github.com/nath-green/hooks
Collection of hooks
https://github.com/nath-green/hooks
Last synced: 3 months ago
JSON representation
Collection of hooks
- Host: GitHub
- URL: https://github.com/nath-green/hooks
- Owner: nath-green
- License: mit
- Created: 2021-03-10T13:51:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-10T16:59:11.000Z (over 4 years ago)
- Last Synced: 2025-03-02T01:54:34.537Z (3 months ago)
- Language: JavaScript
- Size: 52.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hooks
Collection of hooks
- [useFocus](#user-content-usefocus)
- [useFocusOnMount](#user-content-usefocusonmount)## useFocus
Returns `ref` and `setFocus()` to be used on an element which will receive event based focus.
```js
import { useFocus } from '@nath-green/hooks';const { ref, setFocus } = useFocus();
setFocus()}>Focus heading
Focus on me
```### 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.
```js
import { useFocusOnMount } from '@nath-green/hooks';const focusRef = useFocusOnMount();
Focused
```### Use case
When a modal has opened and the focus should be set to the close button.