'How to fix missing dependency warning when using useEffect React Hook? I am using nextjs app

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!



Solution 1:[1]

use the Router instance instead,

 import Router from 'next/router';

It can solve the problem easily.

Solution 2:[2]

Tomerikoo's answer is working.

utilities.py

import time
def utilities_function1():
  print(time.localtime())

def utilities_function2():
  print(time.localtime()+1)

I import the time module once in the top and the subsequent functions will be able to use it.

Additional Answers

Upon further research, I found the answer around best practice on importing modules when I have a parent child folder based on these other stack post 1 and post 2.

We need to import modules that I need in every single python file no matter where the file is located (etc.: parent or child folders).

Also Python only initializes modules if needed (aka once) so I don't need to worry about accidentally importing modules too many times at least for efficiency sake.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2