onAccountChanged event triggers multiple times

When user switch their account onAccountChanged event triggers multiple times. Is there any way to solve this issue?

useEffect(() => {
    var unsubscribe = null;
    if (isAuthenticated && isWeb3Enabled) {
      unsubscribe = Moralis.onAccountChanged(async (accounts) => {
        console.log("onAccountChangedTriggered")
      });
    }
    return () => {
      if (unsubscribe) unsubscribe();
    };  }, [isAuthenticated, isWeb3Enabled]);

can you check if this code runs multiple times also?

unsubscribe = Moralis.onAccountChanged(async (accounts) => {
        console.log("onAccountChangedTriggered")
      });

Do you mean to try this code without useEffect?

no, I mean to add a console log before first line of this code


useEffect(() => {
    console.log("useEffectTriggered")
    var unsubscribe = null;
    if (isAuthenticated && isWeb3Enabled) {
      unsubscribe = Moralis.onAccountChanged(async (accounts) => {
        console.log("onAccountChangedTriggered")
      });
    }
    return () => {
      if (unsubscribe) unsubscribe();
    };  }, [isAuthenticated, isWeb3Enabled]);

Do you mean to try this kind of code?

yes, something like that to see what you get in console

You can have a simple hook to do that in a react way rather. Where you have
const { account } = useMoralis(); and then

useEffect(() => {
    console.log("onAccountChangedTriggered");
    console.log(account);
}, [account]);