Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@reach/observe-rect
Advanced tools
@reach/observe-rect is a utility for observing changes to the size and position of a DOM element. It provides a simple API to track the dimensions and position of an element, which can be useful for responsive design, animations, and other dynamic UI updates.
Observe changes to an element's size and position
This feature allows you to observe changes to the size and position of a DOM element. The `observeRect` function takes an element and a callback function that receives the new rect object whenever the element's size or position changes. The `unobserve` function can be called to stop observing.
const { observeRect } = require('@reach/observe-rect');
const element = document.getElementById('my-element');
const unobserve = observeRect(element, (rect) => {
console.log('Element rect:', rect);
});
// To stop observing
unobserve();
The `resize-observer-polyfill` package provides a polyfill for the ResizeObserver API, which allows you to observe changes to the dimensions of an element. It is similar to @reach/observe-rect but focuses solely on size changes and does not provide position information.
The `react-use-measure` package is a React hook that allows you to measure the size of a DOM element. It is similar to @reach/observe-rect but is designed specifically for React applications and provides a hook-based API.
The `react-resize-detector` package is another React-specific library that provides a way to detect changes to the size of a DOM element. It is similar to @reach/observe-rect but is tailored for use with React components and provides a higher-level API.
Observe the rect of a DOM element.
npm install @reach/observe-rect
# or
yarn add @reach/observe-rect
import observeRect from "@reach/observe-rect";
let node = document.getElementById("some-node");
let rectObserver = observeRect(node, rect => {
console.log("left", rect.left);
console.log("top", rect.top);
console.log("height", rect.height);
console.log("width", rect.width);
});
// start observing
rectObserver.observe();
// stop observing
rectObserver.unobserve();
A lot of things can change the position or size of an element, like scrolling, content reflows and user input. This utility observes and notifies you when your element's rect changes.
MIT License Copyright (c) 2018-present, Ryan Florence
FAQs
Observe the Rect of a DOM element.
The npm package @reach/observe-rect receives a total of 482,188 weekly downloads. As such, @reach/observe-rect popularity was classified as popular.
We found that @reach/observe-rect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.