
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
react-element-resize-events
Advanced tools
This components gives your div/element an onResize event like so:
import { Div } from 'react-element-resize-events';
const MyComponent = ({ text }) => {
const onResize = ({ width, height, init }) => {
console.log(`width: ${width}, height: ${height}${init ? `, and this resize event was due to element being mounted` : ``}.`);
};
<Div onResize={onResize}>{text}</Div>
};
The basic idea is that only the window object has an on resize event. So I capitalize on this fact. The Div component returns a div which is positioned (relative positioning by default) and inside this div the first element is an iframe with absolute positioning and with both width and height set to 100% and visibility: hidden. The children of the Div are then placed next to the iframe.
The idea is the iframe will expand with the parent div and since the iframe has a window element which I attach an onresize event to it, then "forward" the event to the user's input onResize function.
import { ElemWithResizeEvents } from 'react-element-resize-events';
const MyComponent = ({ text }) => {
const onResize = ({ width, height, init }) => {
console.log(`width: ${width}, height: ${height}${init ? `, and this resize event was due to element being mounted` : ``}.`);
};
<ElemWithResizeEvents tagName="h1" onResize={onResize}>{text}</Div>
};
By default the dimentions returned to the onResize function are the inner dimentions of the element (i.e. without margin/padding/border). To override this set getInnerDimentions prop to false as bellow:
import { ElemWithResizeEvents } from 'react-element-resize-events';
const MyComponent = ({ text }) => {
const onResize = ({ width, height, init }) => {
console.log(`width: ${width}, height: ${height}${init ? `, and this resize event was due to element being mounted` : ``}.`);
};
<ElemWithResizeEvents tagName="h1" onResize={onResize} getInnerDimentions={false}>{text}</Div>
};
You can also change the default getInnerDimentions by utilising the setDefaults function as bellow
import { setDefaults } from 'react-element-resize-events';
setDefaults({ getInnerDimentions: false });
You can also change the default tag name used by ElemWithResizeEvents
import { setDefaults } from 'react-element-resize-events';
setDefaults({ tagName: 'span' });
FAQs
Made with create-react-library
The npm package react-element-resize-events receives a total of 0 weekly downloads. As such, react-element-resize-events popularity was classified as not popular.
We found that react-element-resize-events 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
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.