0

The warning I am getting:

Warning: React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array

And the code I write in _app.js:

 const router = useRouter();
  useEffect(() => {
    router.events.on('routeChangeStart', ()=>{
      setProgress(40)
    })
    router.events.on('routeChangeComplete', ()=>{
      setProgress(100)
    })
    // console.log("I am refreshed!")
   try {
    if(localStorage.getItem("cart")){
      setcart(JSON.parse(localStorage.getItem("cart")))
      saveCart(JSON.parse(localStorage.getItem("cart")))
    }
   } catch (error) {
     console.error(error)
     localStorage.clear()
   }
   let token = localStorage.getItem("token");
   if(token){
     setuser({value: token})
     setkeyMaker(Math.random())
   }
  
  }, [router.query])

and I have also imported {useEffect} and {useRouter} from react! Please help me to sort this issue out!

God Coderz
  • 21
  • 3
  • 6
  • This looks like an ongoing issue with ````next.js```` and ````router````. I would suggest you go here and read the comments: https://github.com/vercel/next.js/discussions/29403. The linter is catching it as an error, although it may be working as intended. – AttemptedMastery May 21 '22 at 03:07
  • ignore the linter if your app is working as intended to be – Moein Moeinnia May 21 '22 at 04:01

1 Answers1

0

use the Router instance instead,

 import Router from 'next/router';

It can solve the problem easily.

hotbrainy
  • 331
  • 1
  • 10