You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mq-react

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mq-react

The media queries for your React components. Flow-compatible

1.0.5
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

mq-react

The media queries for your React components. Flow-compatible.

Install

npm install --save mq-react

Usage

Example code

import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import mqDecorate from 'mq-react';

const TestComponent = props => <pre>{JSON.stringify(props, null, '  ')}</pre>;
TestComponent.defaultProps = { mq: undefined };

const Decorated = mqDecorate(TestComponent);

class App extends Component {
  static childContextTypes = {
    mq: PropTypes.objectOf(PropTypes.string),
  };

  /**
   * You can use the context for define app defaults
   */
  getChildContext() {
    return { mq: { isDesktop: '(min-width: 1024px)' } };
  }

  render() {
    return this.props.children;
  }
}

window.addEventListener('DOMContentLoaded', () =>
  ReactDOM.render(
    /**
     * Also you can use the props
     */
    <App>
      <Decorated mq={{ isMobile: '(max-width: 1023px)' }} />
    </App>,
    document.getElementById('app-root'),
  ),
);

Render result

<pre>{
  "mq": {
    "isDesktop": "(min-width: 1024px)",
    "isMobile": "(max-width: 1023px)"
  },
  "isDesktop": true, <!-- true if window width >= 1024px -->
  "isMobile": false  <!-- true if window width < 1024px -->
}</pre>

Keywords

component

FAQs

Package last updated on 14 Jul 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