New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@ryvora/react-use-size

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ryvora/react-use-size

📐✨ Get the width and height of a DOM element in React. Lightweight and efficient!

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

use-size 📐✨

Hello, Dimension Detective! 🕵️‍♂️

The use-size hook is a specialized hook, often simpler than use-rect, focused specifically on getting the width and height of a DOM element. It usually employs a ResizeObserver to efficiently update these dimensions whenever the element resizes.

It's like having a dedicated width and height sensor for your HTML elements! 📏↔️↕️

Why use-size?

  • Performance: If you only need width and height, use-size can be more lightweight than a full use-rect which might track position too.
  • Simplicity: A more focused API for a common use case.
  • Responsive Components: Easily make components adapt to their own size rather than just the viewport.

Basic Usage:

import { useSize } from '@ryvora/react-use-size'; // Hook name might vary
import React, { useRef } from 'react';

function MyResponsiveBox() {
  const boxRef = useRef<HTMLDivElement>(null);
  const size = useSize(boxRef);

  return (
    <div>
      <div
        ref={boxRef}
        style={{
          width: '75%',
          minHeight: '100px',
          border: '2px solid green',
          padding: '10px',
          resize: 'horizontal', // Make it resizable for demo
          overflow: 'auto',
        }}
      >
        Try resizing me horizontally!
        {size && (
          <p>
            Current Width: {size.width}px, Current Height: {size.height}px
          </p>
        )}
        {size && size.width < 300 && <p style={{ color: 'red' }}>I'm getting pretty small!</p>}
      </div>
    </div>
  );
}

Know the dimensions, rule the layout! 👑🖼️

Keywords

react

FAQs

Package last updated on 18 Jun 2025

Did you know?

Socket

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.

Install

Related posts