繁体   English   中英

未安装元掩码时 React 应用程序不呈现

[英]React app does not render when metamask is not installed

每当浏览器中未安装元掩码时,我都会在控制台中收到此错误。:

Uncaught TypeError: window.ethereum is undefined

一切都只是黑屏

简单的解决方案是使用 if 包装任何引用window.ethereum的内容:

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

    // Your extra code here
  }
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM