🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-responsive

Package Overview
Dependencies
Maintainers
2
Versions
71
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

1.2.4
Source
npm
Version published
Weekly downloads
843K
-9.31%
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

css

FAQs

Package last updated on 24 Nov 2016

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