the code below logs 'scrolled' to the console multiple times (at least 10 times), even though using monitorEvents() indicates a single keydown event.
how can i ensure only a single 'scrolled' gets logged to the console without using external libraries
(i wish to cover all possible events that trigger a scroll, hence why i am targeting scroll and not keydown)
import "./App.css";
function App() {
return (
<section
onClick={() => console.log("clicked")}
onScroll={() => console.log("scrolled")}
style={{ height: "100vh", width: "100vw", overflow: "scroll" }}
>
<p style={{ height: "300vh" }}>hi</p>
</section>
);
}
export default App;
I don't know your initial purpose. But I can suggest the following solutions:
This is just an example of a simple hook that might be improved, but I hope you can use it at the first step.