Next Js account account change event fires multiple time

Hello,

I am learning web3 development with Metamask & NextJs.
As suggested in the documentation, I included this block in my code :

 window.ethereum.on("accountsChanged", (accounts) => {
    window.location.reload();
    }
  });

This is working fine, but as soon as I would like to perform a different operation, I noticed the event is fired multiple time in a row. By example this :

 window.ethereum.on("accountsChanged", (accounts) => {
    console.log("event shoot !");
    }
  });

Will result in 6 times “event shoot!” in the console.
This is quite problematic to me as I would like to display a notification on the screen.

Is this a normal behaviour and is there any solution ?

Thank you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.