useFocus
Tracks the focus state of a specified element.
useFocus
Installation
Usage
API
useFocus
Returns a ref and boolean indicating whether the element is currently focused.
Parameters
| Name | Type | Description |
|---|---|---|
| callback? | UseFocusCallback | Optional callback to run in focus and blur HTML element mode. The callback is called with a boolean indicating whether the element is currently focused. |
| T | HTMLElement | The type of the HTML element to focus. |
Returns
| Name | Type | Description |
|---|---|---|
| ref | RefObject<T> | A ref object that can be used to access the HTML element. |
| isFocused | boolean | A boolean indicating whether the element is currently focused. |