GDG-OnCampus-BU / landing-page-WIP

Google Developers Group Bennett University, Landing Page
0 stars 10 forks source link

Minor update in the dependencies of the code: src/components/Navbar.jsx #17

Open vignesh1507 opened 15 hours ago

vignesh1507 commented 15 hours ago

Dependencies in useEffect: You are using scrollPosition as a dependency in the useEffect. This can lead to an infinite loop because every time scrollPosition changes, it will trigger a re-evaluation of the effect. It’s better to use a ref for the scroll position:

const scrollPositionRef = useRef(scrollPosition);

Then update it inside the handleScroll function:

scrollPositionRef.current = currentScrollPos;