react-infinite-any-height
Version:
Wrapper component for react-infinite which auto calculates element heights.
38 lines (31 loc) • 673 B
JSX
import React from "react"
import PropTypes from "prop-types"
const style = {
"display": "block",
"clear": "both",
}
export default class GetHeightWrapper extends React.Component {
static propTypes = {
"addHeight": PropTypes.func,
"children": PropTypes.node,
}
state = {
"height": undefined,
}
componentDidMount = () => {
this.setHeight ()
}
setHeight = () => {
const height = this.node.getBoundingClientRect ().height
this.props.addHeight (height)
this.setState ({ height })
}
render = () => (
<span
ref={(node) => {this.node = node}}
style={style}
>
{this.props.children}
</span>
)
}