@use-it/event-listener
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
@@ -32,5 +32,6 @@ 'use strict'; | ||
react.useEffect(function () { | ||
var isSupported = element && element.addEventListener; | ||
var isRefObject = element == null ? void 0 : element.hasOwnProperty('current'); | ||
var currentTarget = isRefObject ? element.current : element; | ||
if (!isSupported) { | ||
if (currentTarget === null || typeof currentTarget.addEventListener !== 'function') { | ||
return; | ||
@@ -54,5 +55,5 @@ } | ||
}; | ||
element.addEventListener(eventName, eventListener, opts); | ||
currentTarget.addEventListener(eventName, eventListener, opts); | ||
return function () { | ||
element.removeEventListener(eventName, eventListener, opts); | ||
currentTarget.removeEventListener(eventName, eventListener, opts); | ||
}; | ||
@@ -59,0 +60,0 @@ }, [eventName, element, capture, passive, once]); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("global-event-target");exports.default=function(r,n,u){void 0===u&&(u={});var a=e.useRef(),c=u.element,i=void 0===c?t.globalEventTarget:c,o=u.capture,v=u.passive,s=u.once;e.useEffect((function(){a.current=n}),[n]),e.useEffect((function(){if(i&&i.addEventListener){var e=function(e){var t=e;a.current.hasOwnProperty("handleEvent")?a.current.handleEvent(t):a.current(t)},t={capture:o,passive:v,once:s};return i.addEventListener(r,e,t),function(){i.removeEventListener(r,e,t)}}}),[r,i,o,v,s])}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("global-event-target");exports.default=function(r,n,u){void 0===u&&(u={});var a=e.useRef(),c=u.element,o=void 0===c?t.globalEventTarget:c,i=u.capture,v=u.passive,s=u.once;e.useEffect((function(){a.current=n}),[n]),e.useEffect((function(){var e=(null==o?void 0:o.hasOwnProperty("current"))?o.current:o;if(null!==e&&"function"==typeof e.addEventListener){var t=function(e){var t=e;a.current.hasOwnProperty("handleEvent")?a.current.handleEvent(t):a.current(t)},n={capture:i,passive:v,once:s};return e.addEventListener(r,t,n),function(){e.removeEventListener(r,t,n)}}}),[r,o,i,v,s])}; | ||
//# sourceMappingURL=event-listener.cjs.production.min.js.map |
@@ -28,5 +28,6 @@ import { useRef, useEffect } from 'react'; | ||
useEffect(function () { | ||
var isSupported = element && element.addEventListener; | ||
var isRefObject = element == null ? void 0 : element.hasOwnProperty('current'); | ||
var currentTarget = isRefObject ? element.current : element; | ||
if (!isSupported) { | ||
if (currentTarget === null || typeof currentTarget.addEventListener !== 'function') { | ||
return; | ||
@@ -50,5 +51,5 @@ } | ||
}; | ||
element.addEventListener(eventName, eventListener, opts); | ||
currentTarget.addEventListener(eventName, eventListener, opts); | ||
return function () { | ||
element.removeEventListener(eventName, eventListener, opts); | ||
currentTarget.removeEventListener(eventName, eventListener, opts); | ||
}; | ||
@@ -55,0 +56,0 @@ }, [eventName, element, capture, passive, once]); |
@@ -1,4 +0,5 @@ | ||
declare type Options = { | ||
import { MutableRefObject } from 'react'; | ||
export declare type Options = { | ||
/** The element to listen on. Defaults to `global` (i.e. `window`). */ | ||
element?: EventTarget | null; | ||
element?: EventTarget | MutableRefObject<EventTarget | null> | null; | ||
/** Indicates events will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree. */ | ||
@@ -5,0 +6,0 @@ capture?: boolean; |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "A custom React Hook that provides a useEventListener.", | ||
@@ -76,2 +76,3 @@ "license": "MIT", | ||
"@size-limit/preset-small-lib": "^4.9.0", | ||
"@testing-library/react": "^11.2.2", | ||
"@testing-library/react-hooks": "^3.4.2", | ||
@@ -78,0 +79,0 @@ "@types/react": "^17.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32645
195
13