I have a div on which I've added onScroll and triggering a function on scroll event.
import React, { useRef } from 'react';
export const DemoComponent () => {
const myref = useRef(null);
const scrollEvent = () => {
//do something here
//Problem is that this event is triggering on load multiple times even when there is no scroll happening
};
return (
<div onScroll={scrollEvent} ref={myref}></div>
);
};
On load the scroll event triggers multiple times when there is no scrolling yet. Can't seem to figure out how to prevent this.