I followed the instruction from this post Update style of a component onScroll in React.js to register event listener for scroll event.
I have a React component that renders a Table component from the React-Bootstrap library https://react-bootstrap.github.io/
I think I registered the event listener correctly but I am not sure why when I scroll down the table, my handleScroll() callback is not getting invoked. Is it because the event listener is not registered on the actual table itself?
Thanks for taking your time reading my question. Any feedback is appreciated.
Here's a snippet of how I register for the event listener.
handleScroll: function(event) {
console.log('handleScroll invoked');
},
componentDidMount: function() {
console.log('componentDidMount invoked');
window.addEventListener('scroll', this.handleScroll);
},
componentWillUnmount: function() {
console.log('componentWillUnmount invoked');
window.removeEventListener('scroll', this.handleScroll);
},
Here's a snippet of my render function.
render: function() {
var tableRows = this.renderTableRow(this.props.sheet);
return (
<Table striped bordered condensed hover>
<TableHeaderContainer
tableTemplateName={this.props.tableTemplateName}
sheetName={this.props.sheet.name}/>
<tbody>
{tableRows}
</tbody>
</Table>
);
}
– beyonddc Mar 30 '16 at 18:36