react-responsive-mixin
Mixin to develop responsive react components
Last updated 10 years ago by akiran .
MIT · Repository · Bugs · Original npm
$ cnpm install react-responsive-mixin 
SYNC missed versions from official npm registry.

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} />;
  }
});

Current Tags

  • 0.4.0                                ...           latest (9 years ago)

2 Versions

  • 0.3.5                                ...           10 years ago
  • 0.4.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (12)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org