addeventlistener
v2.0.0
Published
`addEventListener` that takes options as an object and returns a function to remove the listener.
Downloads
8
Maintainers
Readme
addeventlistener
addEventListener
that takes options as an object and returns a function to remove the listener.
install
$ npm install addeventlistener
api
addEventListener(element, eventName, listener, options)
import addEventListener from 'addeventlistener'
const removeEventListener = addEventListener(
document.body,
'touchmove',
e => {},
{ passive: false }
)
once(element, eventName, listener, options)
Listen for the event and stop listening after it has occurred once. You can still use the returned function to stop listening if you want to stop listening before the event has occurred once.
import { once } from 'addeventlistener'
const removeEventListener = once(window, 'click', console.log)
CommonJS
const { default: addEventListener, once } = require('addeventlistener')