onAccountsChanged triggers multiple times

I tried out onAccountsChanged event like given below it sometimes triggers multiple times when I switch between accounts in metamask and shows to authenticate in metamask multiple times when I try to link an account.

Is there there anything wrong with the code below? Is there a way to fix this behaviour

useEffect(() => {
    if (isAuthenticated && isWeb3Enabled) {
      Moralis.Web3.onAccountsChanged(async (accounts) => {
        setIsLoading(true)
        if (await checkIfLinked(accounts[0])) {
          await setUserData({ "ethAddress": accounts[0] });
        } else {
          await Moralis.Web3.link(accounts[0]);
          await setUserData({ "ethAddress": accounts[0] });
        }
      });
    }
  }, [isAuthenticated,isWeb3Enabled]);

hmmm it looks like an old syntax, but regardless of your SDK, you should put the onAccountsChanged in a useEffect with no dependencies at all so it’ll just be called once during the component lifecycle?

I tested this this is only being called once