Learn about another feature of useEffect.
useEffect can take on a second argument, which is an array of dependencies. React will keep track of the dependencies and only call your effect if a dependency changes.
You can view this example on Stack Blitz