[英]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.