Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

react-bounds

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-bounds

Element Queries in React

Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
2.8K
6.64%
Maintainers
1
Weekly downloads
 
Created
Source

React Bounds Element Queries in React

  • Like Media Queries - Set min and max values like breakpoints.

  • Use the Bounds in JS - Active bounds are passed down as props.

  • Use the Bounds in CSS - Use the bound names to style the component with CSS.

Installation & Usage

npm install react-bounds --save

Wrap a Component

Require react-bounds into a component. Wrap the export with bounds.wrap and react-bounds will start tracking the width and height of the component.

var React = require('react');
var bounds = require('react-bounds');

var SomeComponent = React.createClass({
  render(){
    return <div>Some Component</div>
  }
});

module.exports = bounds.wrap(SomeComponent);

Define Bounds

Create a bounds method that returns an object with all of the bound information for that component:

var React = require('react');
var bounds = require('react-bounds');

var SomeComponent = React.createClass({

  bounds() {
    return {
      'bound-name': {
        minWidth: 0,
        maxWidth: 500,
      },
    };
  }

  render(){
    return <div>{ this.props.activeBounds }</div>
  }
});

module.exports = bounds.wrap(SomeComponent);

Use with inline styles via ReactCSS

Keywords

react

FAQs

Package last updated on 12 Nov 2016

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