R
Reactiflux

help-threads-react

venus – 14-11 Aug 22

Vvenus8/22/2022
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 });
}}
/>
UUUnknown User8/23/2022
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

help-threads-react

Join Server