@os-design/utils
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -18,3 +18,2 @@ export { default as bodyScroll } from './utils/bodyScroll'; | ||
export { default as useEventListener } from './utils/useEventListener'; | ||
export { default as useWindowEventListener } from './utils/useWindowEventListener'; | ||
export { default as useWindowSize } from './utils/useWindowSize'; | ||
@@ -21,0 +20,0 @@ export * from './utils/color'; |
@@ -40,4 +40,2 @@ "use strict"; | ||
exports.useEventListener = useEventListener_1.default; | ||
var useWindowEventListener_1 = require("./utils/useWindowEventListener"); | ||
exports.useWindowEventListener = useWindowEventListener_1.default; | ||
var useWindowSize_1 = require("./utils/useWindowSize"); | ||
@@ -44,0 +42,0 @@ exports.useWindowSize = useWindowSize_1.default; |
@@ -1,3 +0,3 @@ | ||
declare const useEventListener: (element: EventTarget, type: string, listener: EventListener, options?: boolean | AddEventListenerOptions | undefined) => void; | ||
declare const useEventListener: (type: string, listener: EventListener, options?: boolean | AddEventListenerOptions | undefined, element?: EventTarget | undefined) => void; | ||
export default useEventListener; | ||
//# sourceMappingURL=useEventListener.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const react_1 = require("react"); | ||
const useEventListener = (element, type, listener, options) => { | ||
const isBrowser_1 = __importDefault(require("./isBrowser")); | ||
const useEventListener = (type, listener, options, element) => { | ||
const savedListener = react_1.useRef(); | ||
@@ -10,5 +14,6 @@ react_1.useEffect(() => { | ||
react_1.useEffect(() => { | ||
if (typeof element !== 'object' || | ||
element === null || | ||
!element.addEventListener) | ||
const el = !element && isBrowser_1.default() ? window : element; | ||
if (typeof el !== 'object' || | ||
el === null || | ||
!el.addEventListener) | ||
return () => undefined; | ||
@@ -19,7 +24,7 @@ const eventListener = event => { | ||
}; | ||
element.addEventListener(type, eventListener, options); | ||
return () => element.removeEventListener(type, eventListener); | ||
}, [element, type, options]); | ||
el.addEventListener(type, eventListener, options); | ||
return () => el.removeEventListener(type, eventListener); | ||
}, [type, element, options]); | ||
}; | ||
exports.default = useEventListener; | ||
//# sourceMappingURL=useEventListener.js.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
const react_1 = require("react"); | ||
const useWindowEventListener_1 = __importDefault(require("./useWindowEventListener")); | ||
const useEventListener_1 = __importDefault(require("./useEventListener")); | ||
const isBrowser_1 = __importDefault(require("./isBrowser")); | ||
@@ -19,3 +19,3 @@ const getWindowSize = () => ({ | ||
}, []); | ||
useWindowEventListener_1.default('resize', resizeListener); | ||
useEventListener_1.default('resize', resizeListener); | ||
return size; | ||
@@ -22,0 +22,0 @@ }; |
{ | ||
"name": "@os-design/utils", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "2c9894084c3f65815d8ec5e9016e182658b3705a" | ||
"gitHead": "b56e6afc0cbd26397e75c48a9be8fb4afda98f74" | ||
} |
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
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
36038
90
438