Home > Back-end >  React app does not render when metamask is not installed
React app does not render when metamask is not installed

Time:07-31

I get this error in the console whenever metamask is not installed in the browser.:

Uncaught TypeError: window.ethereum is undefined

It's all just a black screen

CodePudding user response:

The simple solution is to wrap anything that references window.ethereum with an if:

useEffect(() => {
  if(window.ethereum) {
    window.ethereum.on('chainChanged', () => {
      window.location.reload();
    })
    window.ethereum.on('accountsChanged', () => {
      window.location.reload();
    })

    // Your extra code here
  }
})
  • Related