onChangeAccounts is triggering multiple times

Iโ€™m trying to let a user link an address and the registered on change function triggers multiple times when changing metamask accounts:

  useEffect(() => {
    console.log('running hook');

    (Moralis as any).onAccountsChanged(async (accounts: string[]) => {
      console.log({ user: Moralis.User.current() }, 'changed accounts');

      if (!Moralis.User.current()) return;

      const confirmed = confirm('Link this address to your account?');

      if (confirmed) {
        await (Moralis as any).link(accounts[0]);
  }, [Moralis, enableWeb3]);

I confirmed the hook only runs once.

Thereโ€™s also no good way to remove the on change handler (say when a component unmounts in a react app).

Is there anyone else running into this issue?

you could try to check in that hook if the user already has that address in his accounts and skip the link if he already has that address associated

The thing is that the function runs many times even before the user is able to sign the requesr via metamask. Iโ€™ll post a video in a bit.

Im too facing the same issue were you able to find a solution?