useActiveElement
Hook that returns the active element
elements
low
test coverage
Last changed: 24 days ago
Installation
Library
CLI
Manual
typescript
import { useActiveElement } from '@siberiacancode/reactuse';Usage
typescript
## Demo const activeElement = useActiveElement(ref);
// or
const { ref, value } = useActiveElement();Api
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| target? | HookTarget | window | The target element to observe active element changes |
Returns
ActiveElement | null
Returns
{ ref: StateRef<Element>; activeElement: ActiveElement | null }
Type declaration
typescript
import type { HookTarget } from '@/utils/helpers';
import type { StateRef } from '../useRefState/useRefState';
export interface UseActiveElementReturn<ActiveElement extends HTMLElement = HTMLElement> {
value: ActiveElement | null;
}
export interface UseActiveElement {
(): UseActiveElementReturn;
<Target extends Element, ActiveElement extends HTMLElement = HTMLElement>(
target?: never
): {
ref: StateRef<Target>;
} & UseActiveElementReturn<ActiveElement>;
<ActiveElement extends HTMLElement = HTMLElement>(
target: HookTarget
): UseActiveElementReturn<ActiveElement>;
}Source
Source • DemoContributors
D
B