
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
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 6 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.