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

react-media-hoc

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-media-hoc

React HOC for media queries

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

React Media

This projects provides a simple and straight forward method for a React application to adopt and respond to browser media. Most of the time adding media queries to project's CSS is the right way to go. However there are times when an application component needs to detect the resolution of a media device or respond to a change to media/device orientation. This simple Higher Order Component helps you to do just that.

Installation

npm install react-media-hoc --save

or

yarn add react-media-hoc

Usage

import responsiveToMedia from 'react-media-hoc'

// A simple stateless component will do
const MyResponsiveComponent = ({portrait, mobile}) => (
  <div>
    {
      portrait && <p>You are in portrait mode</p>
    }
    {
      mobile && <p>You are on mobile device</p>
    }
  </div>
)

export default responsiveToMedia({
  portrait: '(orientation: portrait)',
  mobile: { maxWidth: 300 }
})(MyResponsiveComponent)

responsiveToMedia call accepts an object with a list of media queries to monitor. The keys of the object denote the props that will be passed to wrapped component (MyResponsiceComponent in the example above) and the value of those props will be a boolean corresponding to the media query matching or not.

The media query can be expressed as a string or as an object which will be parsed using json2mq.

Keywords

react

FAQs

Package last updated on 19 May 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