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