How to add scroll event in react component

前端 未结 6 2026
逝去的感伤
逝去的感伤 2021-01-03 20:39

I\'m trying to add an onScroll event on a table. This is what I\'ve tried:

componentDidMount() {
    ReactDOM.findDOMNode(this.refs.table).addEv         


        
6条回答
  •  醉话见心
    2021-01-03 21:25

    I was looking to do something similar. Adding the event listener to the window instead of the ReactDom.findDOMNode worked for me...

    componentDidMount() {
        window.addEventListener('scroll', this.handleScrollToElement);
    }
    
    componentWillUnmount() {
        window.removeEventListener('scroll', this.handleScrollToElement);
    }
    
    handleScrollToElement(event) {
        console.log('Fired ' + event)
    }
    

提交回复
热议问题