[英]I am trying to create a react website and add hooks in it but face this erros
import { useState } from "react";
const TronWeb = require("tronweb");
const [lpLogged, setlpLogged] = useState(true);
async function getTronWeb() {
if (window.tronWeb && window.tronWeb.defaultAddress.base58) {
return window.tronWeb;
}
return null;}
let curweb = getTronWeb ();
async function initWindow() {
if (curweb == null) {
setlpLogged((lpLogged) => false);
alert.show("We were unable to find any suitble providder.");
} else {
setlpLogged((lpLogged) => true);
}
}
<button onclick={initWindow}>Can you get tronweb from tronlink?</button>
Compiled with problems:X
./src/App.js 中的錯誤 12:35-39
在“./components/Body”中找不到導出“默認”(導入為“Body”)(模塊沒有導出)
錯誤
[eslint] src\components\Body.js Line 8:33: React Hook "useState" 不能在頂層調用。 React Hooks 必須在 React 函數組件或自定義 React Hook 函數中調用 react-hooks/rules-of-hooks
搜索關鍵字以了解有關每個錯誤的更多信息。
這是我在運行它時遇到的錯誤
嘗試修復導入: import React,{useState} from "react";
加上檢查 Body 組件中的導出方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.