Use npm to install:
npm install provide-dimensions
import React, { PropTypes, Component } from 'react';
import provideDimensions from 'provide-dimensions';
@provideDimensions
export default class MyComponent extends Component {
static propTypes = {
dimensions: PropTypes.shape({
width: PropTypes.number,
height: PropTypes.number
}).isRequired
}
render() {
const { width, height } = this.props.dimensions;
return (
<div style={{ width, height }} />
);
}
}
Code and documentation copyright 2017 Jon Brennecke. Code released under the MIT license. Docs released under Creative Commons.