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