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.
@rehooks/component-size
Advanced tools
@rehooks/component-size
React hook for determining the size of a component
Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.
You'll need to install
react
,react-dom
, etc at^16.7.0-alpha.0
yarn add @rehooks/component-size
import { useRef } from 'react'
import useComponentSize from '@rehooks/component-size'
function MyComponent() {
let ref = useRef(null)
let size = useComponentSize(ref)
// size == { width: 100, height: 200 }
let { width, height } = size
let imgUrl = `https://via.placeholder.com/${width}x${height}`
return (
<div style={{ width: '100%', height: '100%' }}>
<img ref={ref} src={imgUrl} />
</div>
)
}
Resize Observer is the API is used to determine if an element is resized. Browser support is pretty good in Chrome, but is still missing support in other major browsers.
You can import the polyfill directly from here
yarn add resize-observer-polyfill
Then import it in your app:
import 'resize-observer-polyfill'
If you are using Webpack (or similar) you could use dynamic imports, to load the Polyfill only if needed. A basic implementation could look something like this:
loadPolyfills()
.then(() => /* Render React application now that your Polyfills are ready */)
/**
* Do feature detection, to figure out which polyfills needs to be imported.
**/
function loadPolyfills() {
const polyfills = []
if (!supportsResizeObserver()) {
polyfills.push(import('resize-observer-polyfill'))
}
return Promise.all(polyfills)
}
function supportsResizeObserver() {
return (
'ResizeObserver' in global &&
'ResizeObserverEntry' in global &&
'contentRect' in ResizeObserverEntry.prototype
)
}
FAQs
React hook for component-size
The npm package @rehooks/component-size receives a total of 42,035 weekly downloads. As such, @rehooks/component-size popularity was classified as popular.
We found that @rehooks/component-size demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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.