venus – 14-11 Aug 22

Hello. I want to set state on true when is user scrolled on top/bottom, but I want to avoid re-rendering whole component on each scroll. What would you recommend me to do?
const [isReached, setIsReached] = useState({ top: false, bottom: false });

<div
onScroll={(e: any) => {
const top = e.target.scrollTop === 0;
const bottom =
e.target.scrollHeight - e.target.scrollTop ===
e.target.clientHeight;

setIsReached({ bottom: bottom, top: top });
}}
/>
const [isReached, setIsReached] = useState({ top: false, bottom: false });

<div
onScroll={(e: any) => {
const top = e.target.scrollTop === 0;
const bottom =
e.target.scrollHeight - e.target.scrollTop ===
e.target.clientHeight;

setIsReached({ bottom: bottom, top: top });
}}
/>
UU
Unknown User603d ago