I want to change the id if the mouse is scrolled down or up the id is automatically replaced according to the scroll position
const ref = useRef();
const handleScroll = useCallback(() => {
console.log("scrolling");
}, []);
useEffect(() => {
const div = ref.current;
div.addEventListener('scroll', handleScroll);
}, [handleScroll]);
return (
<React.Fragment>
<Indicator />
<section
id="story"
ref={ref}
>
<Story />
</section>
<section id="company">
<Company />
</section>
<section id="milestone">
<Milestone />
</section>
<section id="business">
<Business />
</section>
<section id="business_maps">
<Maps />
</section>
</React.Fragment>
)
I've made a scroll function in the indicator component, it works fine because it's clicked
For example, when the function is clicked, it will go to the content according to the id that was clicked
const scrollToElement = (id, value) => {
const element = document.getElementById(`${value}`);
element.scrollIntoView({ behavior: 'smooth' });
setActive(id);
}
{indicator.map(list => (
<div
id={list.id}
key={list.id}
className={`${list.id === active ? `${style.active} ${style.dot}` `${style.dot}`}`}
onClick={() => scrollToElement(list.id, list.name)}
>
<small className={style.hide}>{list.name}</small>
</div>
))}