diff --git a/src/components/AutoSizer.js b/src/components/AutoSizer.js new file mode 100644 index 0000000..4535a96 --- /dev/null +++ b/src/components/AutoSizer.js @@ -0,0 +1,38 @@ +import React from 'react' +import PropTypes from 'prop-types' + +export default class AutoSizer extends React.Component { + static propTypes = {} + + static defaultProps = {} + + state = { + size: { + width: 0, + height: 0, + }, + } + + ref = React.createRef() + + componentDidMount() { + const container = this.ref.current + if (container) { + this.setState({ + size: { + width: container.offsetWidth, + height: container.offsetHeight, + }, + }) + } + } + + render() { + const { size } = this.state + return ( +
+ {this.props.children(size)} +
+ ) + } +}