lodash throttling - Function not called when binded

Viewed 32

I have a div and when scrolling this particular div i want to fire a certain function. To limit the number of functions firing when scrolling, i have used lodash throttling feature. But for some reason binding the function like below prevents the events to be passed to the function.

This is how i've used throttle feature

this.listenScrollEvent = _.throttle(this.onWidgetScroll, 2000).bind(this);

My div looks something like below

    <div
        id={this.props.isInfiniteScoll ? 'infinite' : ''}
        onScroll={this.listenScrollEvent}

        {this.renderCards()}
    </div>

And finally the function

listenScrollEvent(e) {
   this.onWidgetScroll(e);
}

I have tried like this as well

onScroll={(e) => this.listenScrollEvent(e)}
0 Answers
Related