
Research
/Security News
11 Malicious NuGet Tools Pose as Game Cheats to Drop a Windows Host-Surveillance Payload
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.
use-element-fit
Advanced tools
useElementFit is a React hook that allows you to measure and element's based on certain restraints, similar to object-fit in CSS.
useElementFit is a React hook that allows you to measure and element's based on certain restraints, similar to object-fit in CSS.
Working with canvas or more complex uses of object-fit often makes it useful to calculate the width/height and x/y values of a element or object, this effect helps you do this.
See useElementFit in action
import React from 'react';
import { useElementFit, ScaleMode } from 'use-element-fit';
const App = () => {
const {ref, width, height} = useElementFit(0.5, 1, ScaleMode.COVER); // half the width and the full height of parent element
return (
<div ref={ref}>
<div style={{
width: `${width}px`,
height: `${height}px`,
}}>
Size: {width}x{height}
</div>
</div>
);
};
useElementFit(ratioX, ratioY, scaleMode?, alignmentX?, alignmentY?, maxWidth?, maxHeight?)
ratioX
Type: number
ratioX to 0.5 and ratioY to 1 will result in half the width and the full height of the elementratioY
numberratioX to 1 and ratioY to 0.5 will result in half the height and the full width of the elementscaleMode
ScaleMode or stringScaleMode.COVERcover, contain and align-only.alignmentX
number0.5alignmentX to 1 will position the result at the very right edge, and vice versa for 0alignmentY
number0.5alignmentY to 1 will position the result at the very bottom edge, and vice versa for 0maxWidth
numbermaxHeight
numberuseElementFit returns and object with the following properties:
ref
React.RefObjectwidth
numberheight
numberx
numbery
numberScaleMode is a TypeScript enum which determines the type of scaling in useElementFit
ScaleMode.COVER
ScaleMode.CONTAIN
ScaleMode.ALIGN_ONLY
ALIGN_ONLY performs no width/height calculation and only aligns vertically and horizontally the result based on the supplied alignmentX and alignmentY within the container.use-resize-observer internallyMIT
FAQs
useElementFit is a React hook that allows you to measure and element's based on certain restraints, similar to object-fit in CSS.
The npm package use-element-fit receives a total of 25 weekly downloads. As such, use-element-fit popularity was classified as not popular.
We found that use-element-fit 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.

Research
/Security News
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.

Research
/Security News
4 compromised asyncapi packages deliver miasma botnet loader on macOS, Linux and Windows.

Research
/Security News
A compromised jscrambler npm release added a malicious preinstall hook that runs hidden native binaries on Linux, macOS, and Windows.