
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
rc-resize-observer
Advanced tools
Supply Chain Security
Vulnerability
Quality
Maintenance
License
The rc-resize-observer npm package is a React component that allows you to monitor and respond to changes in the size of a DOM element. It leverages the ResizeObserver API to provide a simple and efficient way to perform actions based on element or viewport resizing. This can be particularly useful in responsive design, where you might need to adjust layout or content based on the available space.
Observing size changes
This feature allows you to wrap any component or element with the ResizeObserver component. It will then call the provided `onResize` callback whenever the size of the wrapped element changes, passing an object containing the new size information.
import ResizeObserver from 'rc-resize-observer';
function MyComponent() {
return (
<ResizeObserver
onResize={(sizeInfo) => {
console.log('New size:', sizeInfo);
}}
>
<div>Resize me!</div>
</ResizeObserver>
);
}
This package provides a polyfill for the ResizeObserver API, which is the underlying technology used by rc-resize-observer. While not a React-specific solution, it can be used in React projects to achieve similar functionality by manually attaching and managing observers in component lifecycle methods.
react-resize-detector is another React component designed to listen for element size changes. It offers a similar API to rc-resize-observer but includes additional features such as the ability to specify a specific element to observe via a ref, and the option to throttle or debounce the resize events to improve performance.
Resize observer for React.
https://react-component.github.io/resize-observer/
import ResizeObserver from 'rc-resize-observer';
import { render } from 'react-dom';
render(
<ResizeObserver
onResize={() => {
console.log('resized!');
}}
>
<textarea />
</ResizeObserver>,
mountNode,
);
Property | Type | Default | Description |
---|---|---|---|
disabled | boolean | false | |
onResize | ({ width, height }) => void | - | Trigger when child node resized |
npm install
npm start
rc-resize-observer is released under the MIT license.
FAQs
Resize observer for React
The npm package rc-resize-observer receives a total of 1,787,055 weekly downloads. As such, rc-resize-observer popularity was classified as popular.
We found that rc-resize-observer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.