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');
enableWeb3();
(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?