From 943df45dfd32115c36e41fe36552d2700627f2f0 Mon Sep 17 00:00:00 2001 From: swapnilnarad2000 Date: Mon, 5 Feb 2024 12:27:31 +0530 Subject: [PATCH] Fixed navbar section warning --- src/Components/NavbarSection.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Components/NavbarSection.js b/src/Components/NavbarSection.js index a78866a..d7ae231 100644 --- a/src/Components/NavbarSection.js +++ b/src/Components/NavbarSection.js @@ -2,6 +2,7 @@ import Container from 'react-bootstrap/Container'; import Nav from 'react-bootstrap/Nav'; import Navbar from 'react-bootstrap/Navbar'; import React, { useState, useEffect } from 'react'; +import { useCallback } from 'react'; import Image from 'react-bootstrap/Image'; @@ -16,7 +17,7 @@ let NavbarSection = () => { const [overlay, setOverlay] = useState(false); const [lastScrollY, setLastScrollY] = useState(0); - const controlNavbar = () => { + const controlNavbar = useCallback(() => { if(window.scrollY === 0){ setOverlay(false); } @@ -29,7 +30,7 @@ let NavbarSection = () => { // remember current page location to use in the next move setLastScrollY(window.scrollY); - }; + }, [lastScrollY]); useEffect(() => { window.addEventListener('scroll', controlNavbar); @@ -38,7 +39,7 @@ let NavbarSection = () => { return () => { window.removeEventListener('scroll', controlNavbar); }; - }, [lastScrollY]); + }, [lastScrollY, controlNavbar]); return (