react-breakpointable
v0.2.0
Published
A React mixin to respond to changing viewport breakpoints
Downloads
7
Readme
breakpointable
A React Mixin to respond to changing viewport breakpoints
Integration
Three steps:
- Add the mixins
- Define your breakpoints
- Add a change listener
var Breakpointable = require('react-breakpointable');
var MyComponent = React.createClass({
mixins: [Breakpointable],
breakpoints [
{name: 'mobile', width: 0},
{name: 'desktop', width: 990},
],
onBreakpointChange(breakpointName) {
// Act on breakpoint
this.setState({
breakpoint: breakpointName
});
}
render: function () {
return <div class={"my-component my-component-" + breakpointName}>
{breakpointName == "desktop" &&
<h1>Desktop-only</h1>}
{breakpointName == "mobile" &&
<h1>Mobile-only</h1>}
</div>
}
});