react-page-width
React mixin so a component can always know the current page width
Last updated 10 years ago by kylemathews .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install react-page-width 
SYNC missed versions from official npm registry.

react-page-width

High performance React mixin so a component can always know the current page width.

Creates only one window resize event listener so 100s of components can easily listen in to page width changes.

Install

npm install react-page-width

Usage

var PageWidthMixin = require('react-page-width')

module.exports = React.createClass({
  mixins: [PageWidthMixin],
  render: function() {
    // this.state.pageWidth is available!
    if (this.state.pageWidth > 700) {
      <div>Big page</div>
    }
    else {
      <div>Small page</div>
    }
  }
})

Server side rendering

You can also pass in an initialPageWidth value so a value is available for server side rendering.

Current Tags

  • 1.0.1                                ...           latest (10 years ago)

2 Versions

  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 3
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (15)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE