Skip to content

useDocumentEvent

Hook attaches an event listener to the document object for the specified event

browser
low
test coverage
Last changed: 4 months ago

Installation

Library
CLI
Manual
typescript
import { useDocumentEvent } from '@siberiacancode/reactuse';

Usage

typescript
useDocumentEvent('click', () => console.log('clicked'));
## Demo

Api

Parameters

NameTypeDefaultNote
eventEvent-The event to listen for.
listener(event: DocumentEventMap[Event]) => void-The callback function to be executed when the event is triggered
options?UseEventListenerOptions-The options for the event listener

Returns

void

Type declaration

typescript
import type { UseEventListenerOptions } from '../useEventListener/useEventListener';

Source

SourceDemo

Contributors

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.