Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-dom-resize-observer

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-dom-resize-observer - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

6

dist/hooks/useResizeObserver.d.ts

@@ -1,7 +0,7 @@

/// <reference types="react" />
export declare function useResizeObserver<T extends Element | null>(ref?: React.MutableRefObject<T>, onResize?: (entry: ResizeObserverEntry) => void): {
import React from "react";
export declare function useResizeObserver<T extends Element | null>(elementRef?: React.MutableRefObject<T>, onResize?: (entry: ResizeObserverEntry) => void): {
entry: ResizeObserverEntry | null;
observer: (el: T) => void;
disconnect?: () => void;
disconnect: () => void;
};
//# sourceMappingURL=useResizeObserver.d.ts.map

@@ -5,15 +5,12 @@ "use strict";

const react_1 = require("react");
function useResizeObserver(ref, onResize) {
const [state, setState] = (0, react_1.useState)(false);
function useResizeObserver(elementRef, onResize) {
const resizeObserver = (0, react_1.useRef)(null);
const observerEntry = (0, react_1.useRef)(null);
const disconnect = (0, react_1.useRef)(() => {
/** */
/** Initialized as a no-op */
});
const unobserve = (0, react_1.useRef)(() => {
/** */
/** Initialized as a no-op */
});
/** Set when */
const isElementObserved = (0, react_1.useRef)(false);
/** Pass a callback to set the observed element. */
/** Callback with the same signature as an elements `ref` attribute. */
const observer = (0, react_1.useCallback)((el) => {

@@ -31,3 +28,2 @@ if (el === null)

resizeObserver.current.observe(el);
isElementObserved.current = true;
disconnect.current = () => {

@@ -42,24 +38,14 @@ var _a;

}, [onResize]);
/** Set the element reference as a side-effect if they already have a ref. */
/** If they have provided a ref of their own, set it the observer here. */
(0, react_1.useEffect)(() => {
const currentElement = ref === null || ref === void 0 ? void 0 : ref.current;
if (currentElement === undefined ||
currentElement === null ||
isElementObserved.current === true)
if ((elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === undefined || elementRef.current === null)
return;
observer(currentElement);
}, []);
/** If there is an element reference passed in, set to true to prevent observer callback running twice. */
observer(elementRef.current);
}, [observer, elementRef]);
/** Unobserve and disconnect when unmounted. */
(0, react_1.useEffect)(() => {
const currentElement = ref === null || ref === void 0 ? void 0 : ref.current;
if (currentElement === undefined || currentElement === null)
return;
isElementObserved.current = true;
}, []);
/** Unobserve and disconnect when unmounted. */
(0, react_1.useEffect)(() => () => {
if (resizeObserver.current !== null) {
return () => {
unobserve.current();
disconnect.current();
}
};
}, []);

@@ -66,0 +52,0 @@ return {

{
"name": "react-dom-resize-observer",
"version": "0.1.9",
"version": "0.1.10",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc