Socket
Socket
Sign inDemoInstall

react-responsive-mixin

Package Overview
Dependencies
4
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-responsive-mixin

Mixin to develop responsive react components


Version published
Weekly downloads
2.3K
decreased by-0.7%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-responsive-mixin

react-responsive-mixin makes building responsive components easy

This mixin adds method called media() to the react component. This is a wrapper around enquire.js

Demo

Usage

this.media(query, handler)
query

query is a media query definition either in string or object format. This mixin internally uses json2mq to convert media query from object to string format.

handler

handler is a function that needs to be executed when media query matches. handler can also be an object according to enquire.js API

Example
var React = require('react');
var ResponsiveMixin = require('react-responsive-mixin');

var Component = React.createClass({
  mixins: [ResponsiveMixin],
  getInitialState: function () {
    return { url: '/img/large.img' };
  },
  componentDidMount: function () {
    this.media({maxWidth: 600}, function () {
      this.setState({url: '/img/small.jpg'});
    }.bind(this));
    this.media({minWidth:601, maxWidth: 1024}, function () {
      this.setState({url: '/img/medium.jpg'});
    }.bind(this));
    this.media({minWidth: 1025}, function () {
      this.setState({url: '/img/large.jpg'});
    }.bind(this));
  },
  render: function () {
    return <img src={this.state.url} />;
  }
});

Keywords

FAQs

Last updated on 01 Sep 2016

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc