Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-container-dimensions
Advanced tools
Wrapper component that detects element resize and passes new dimensions down the tree. Based on [element-resize-detector](https://github.com/wnr/element-resize-detector)
Wrapper component that detects parent (container) element resize and passes new dimensions down the tree. Based on element-resize-detector.
npm install --save react-container-dimensions
It is especially useful when you create components with dimensions that change over time and you want to explicitely pass the container dimensions to the children. For example, SVG visualization needs to be updated in order to fit into container.
It uses getBoundingClientRect()
and passes values for all top
, right
, bottom
, left
, width
, height
CSs attributes down the tree.
top
, right
, bottom
, left
, width
, height
as props.<ContainerDimensions>
<MyComponent/>
</ContainerDimensions>
{ width: number, height: number }
as an argument and it expects the output to be a React Component or an element.<ContainerDimensions>
{ ({ height }) => <MyComponent height={height}/> }
</ContainerDimensions>
It does not create a new element in the DOM but relies on the parentNode
which must be present. So, basically, it acts as a middleware to pass the dimensions of your styled component to your children components. This makes it very easy to integrate with your existing code base.
For example, if your parent container has display: flex
, only adjacent children will be affected by this rule. This means if your children rely on flex
CSS property, you can't wrap it in a div anymore since this will break the flexbox flow.
So this won't work anymore:
<div style="display: flex">
<div>
<div style="flex: 1">...</div>
</div>
</div>
react-container-dimensions
doesn't change the resulting HTML markup, so it remains:
<div style="display: flex">
<div style="flex: 1">...</div>
</div>
Let's say you want your SVG visualization to always fit into the container. In order for SVG to scale elements properly it is required that width
and height
attributes are properly set on the svg
element. Imagine the following example
It's hard to keep dimensions of the container and the SVG in sync. Especially, when you want your content to be resplonsive (or dynamic).
export const myVis = () => (
<div className="myStyles">
<svg width={600} height={400}>
{/* SVG contents */}
</svg>
<div>
)
This will resize and re-render the SVG each time the div
dimensions are changed. For instance, when you change CSS for .myStyles
.
import ContainerDimensions from 'react-container-dimensions'
export const myVis = () => (
<div className="myStyles">
<ContainerDimensions>
{ ({ width, height }) =>
<svg width={width} height={height}>
{/* SVG contents */}
</svg>
}
</ContainerDimensions>
<div>
)
and a few others...
FAQs
Wrapper component that detects element resize and passes new dimensions down the tree. Based on [element-resize-detector](https://github.com/wnr/element-resize-detector)
The npm package react-container-dimensions receives a total of 20,158 weekly downloads. As such, react-container-dimensions popularity was classified as popular.
We found that react-container-dimensions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.