For some reason this.getVisible()
is not firing on scroll/resize events. Can someone tell me what the problem is?
import React, { Component } from 'react' const ZeroSum = ({ selector, ...passedProps, }) => WrappedComponent => class WithZeroSum extends Component { constructor(props) { super(props) this.selector = document.querySelector(selector) this.state = { zeroSum: 0, } } componentWillMount() { window.addEventListener('scroll resize', () => this.getVisible()) this.getVisible() } componentWillUnmount() { window.removeEventListener('scroll resize', () => this.getVisible()) } getVisible() { const vHeight = document.documentElement.clientHeight const eTop = this.selector.getBoundingClientRect().top return this.setState({ zeroSum: Math.max(0, vHeight - eTop) }) } render() { const { zeroSum } = this.state const props = { ...this.props, ...passedProps } console.log(zeroSum) return <WrappedComponent {...props} zeroSum={zeroSum} /> } } export default ZeroSum