Struggling with the document scroll event
Unanswered
gin posted this in #help-forum
ginOP
Yo, im trying to attach a scroll listener to a div element but its not firing
4 Replies
ginOP
This is my snippet of the relevant code:
Problem is for some reason the ref is always null
useEffect(() => {
const scrollContainer = scrollRef.current;
if (!scrollContainer) return;
scrollContainer.addEventListener("scroll", onScroll);
return () => {
if (scrollContainer) {
scrollContainer.removeEventListener("scroll", onScroll);
}
};
}, [modalOpen]);
{player && modalOpen ? (
<>
.......
<div
style={{
maxHeight: "300px",
overflowY: "auto",
}}
ref={scrollRef}
>
<div dangerouslySetInnerHTML={{__html: applyConfigProfile.requirements}} />
</div>
.......
Problem is for some reason the ref is always null
ginOP
bump
ginOP
bump
ginOP
i fixed it with the onScroll event