useGlobalListener
API
import useGlobalListener from '@restart/hooks/useGlobalListener'
useGlobalListener
<K>(event: K, handler: DocumentEventHandler<K>, capture: boolean | AddEventListenerOptions) => voidAttaches an event handler outside directly to the
document
, bypassing the react synthetic event system.useGlobalListener('keydown', (event) => {console.log(event.key)})Parameters
event
KThe DOM event name
handler
(this: Document, ev: DocumentEventMap[K]) => anyAn event handler
capture
boolean | AddEventListenerOptionsWhether or not to listen during the capture event phase
Return Value void