Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-responsive

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-responsive

Media queries in react for responsive design

  • 4.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
675K
increased by6.91%
Maintainers
2
Weekly downloads
 
Created

What is react-responsive?

The react-responsive package is a utility for managing media queries in React applications. It allows developers to create responsive components that adapt to different screen sizes and orientations.

What are react-responsive's main functionalities?

Media Query Component

This feature allows you to use media queries directly within your React components. The useMediaQuery hook can be used to conditionally render content based on the screen size, orientation, and resolution.

import { useMediaQuery } from 'react-responsive';

const Example = () => {
  const isDesktopOrLaptop = useMediaQuery({ minWidth: 1224 });
  const isBigScreen = useMediaQuery({ minWidth: 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

This feature allows you to use the MediaQuery component to wrap children elements that should only be rendered if the media query matches. This is useful for conditionally rendering parts of your component tree based on media queries.

import { MediaQuery } from 'react-responsive';

const Example = () => (
  <div>
    <MediaQuery minWidth={1224}>
      <p>You are a desktop or laptop</p>
    </MediaQuery>
    <MediaQuery minWidth={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 react-responsive

Keywords

FAQs

Package last updated on 16 Nov 2017

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