Socket
Socket
Sign inDemoInstall

react-use-size

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-size

React hooks to measure things


Version published
Weekly downloads
3.4K
decreased by-3.35%
Maintainers
1
Weekly downloads
 
Created
Source

semantic-release

react-use-size

A collection of hooks to measure things in React

Installation

npm i react-use-size
// or
yarn add react-use-size

Usage

useWindowSize

import { useWindowSize } from "react-use-size";

const YourComponent = () => {
  const { height, width } = useWindowSize();

  return (
    <React.Fragment>
      <p>Height: {height}</p>
      <p>Width: {width}</p>
    </React.Fragment>
  );
};

useComponentSize

import { useComponentSize } from "react-use-size";

const YourComponent = () => {
  const { ref, height, width } = useComponentSize();

  return (
    <React.Fragment>
      <div ref={ref}>
        Component
        <p>Height: {height}</p>
        <p>Width: {width}</p>
      </div>
    </React.Fragment>
  );
};

useBreakpoint

import { useBreakpoint } from "react-use-size";

const YourComponent = () => {
  const isSmall = useBreakpoint(640);

  if (isSmall) {
    return <SmallComponent />
  } else {
    return <DefaultComponent />
  }
};

useBreakpoints

import { useBreakpoints } from "react-use-size";

const YourComponent = () => {
  const [isSmall, isMedium] = useBreakpoint([640, 1024]);

  if (isSmall) {
    return <SmallComponent />
  } else if(isMedium) {
    return <MediumComponent />
  } else {
    return <DefaultComponent />
  }
};

How to contribute?

This repo enforce commit style so the release process is automatic. Commits must look like:

SUBJECT: message starting with a lowercase

where SUBJECT is one of:

  • build
  • ci
  • chore
  • docs
  • feat
  • fix
  • perf
  • refactor
  • revert
  • style
  • test

A commit including BREAKING CHANGE: in the body will create a new major release.

More details about the conventions are available here and here.

Found a problem?

Please open an issue or submit a PR, we will be more than happy to help

FAQs

Package last updated on 21 Jan 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc