Socket
Socket
Sign inDemoInstall

@types/react-responsive

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/react-responsive

TypeScript definitions for react-responsive


Version published
Weekly downloads
150K
increased by12.39%
Maintainers
1
Weekly downloads
 
Created

What is @types/react-responsive?

@types/react-responsive provides TypeScript definitions for the react-responsive library, which allows developers to create responsive components that adapt to different screen sizes and media queries.

What are @types/react-responsive's main functionalities?

Media Query Component

The useMediaQuery hook allows you to create responsive components by defining media queries. The component will render different content based on the screen size and orientation.

import { useMediaQuery } from 'react-responsive';

const ExampleComponent = () => {
  const isDesktopOrLaptop = useMediaQuery({ minDeviceWidth: 1224 });
  const isBigScreen = useMediaQuery({ minDeviceWidth: 1824 });
  const isTabletOrMobile = useMediaQuery({ maxWidth: 1224 });
  const isPortrait = useMediaQuery({ orientation: 'portrait' });
  const isRetina = useMediaQuery({ minResolution: '2dppx' });

  return (
    <div>
      {isDesktopOrLaptop && <p>You are a desktop or laptop</p>}
      {isBigScreen && <p>You have a huge screen</p>}
      {isTabletOrMobile && <p>You are a tablet or mobile phone</p>}
      {isPortrait && <p>You are in portrait orientation</p>}
      {isRetina && <p>You are retina</p>}
    </div>
  );
};

Media Query Component with Children

The MediaQuery component allows you to wrap content that should only be displayed if the media query matches. This is useful for conditionally rendering parts of your UI based on screen size and other media features.

import { MediaQuery } from 'react-responsive';

const ExampleComponent = () => (
  <div>
    <MediaQuery minDeviceWidth={1224}>
      <p>You are a desktop or laptop</p>
    </MediaQuery>
    <MediaQuery minDeviceWidth={1824}>
      <p>You have a huge screen</p>
    </MediaQuery>
    <MediaQuery maxWidth={1224}>
      <p>You are a tablet or mobile phone</p>
    </MediaQuery>
    <MediaQuery orientation="portrait">
      <p>You are in portrait orientation</p>
    </MediaQuery>
    <MediaQuery minResolution="2dppx">
      <p>You are retina</p>
    </MediaQuery>
  </div>
);

Other packages similar to @types/react-responsive

FAQs

Package last updated on 07 Nov 2023

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