简体   繁体   English

我正在尝试创建一个反应网站并在其中添加挂钩,但面临这个错误

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

ERROR in ./src/App.js 12:35-39 ./src/App.js 中的错误 12:35-39

export 'default' (imported as 'Body') was not found in './components/Body' (module has no exports)在“./components/Body”中找不到导出“默认”(导入为“Body”)(模块没有导出)

ERROR错误

[eslint] src\components\Body.js Line 8:33: React Hook "useState" cannot be called at the top level. [eslint] src\components\Body.js Line 8:33: React Hook "useState" 不能在顶层调用。 React Hooks must be called in a React function component or a custom React Hook function react-hooks/rules-of-hooks React Hooks 必须在 React 函数组件或自定义 React Hook 函数中调用 react-hooks/rules-of-hooks

Search for the keywords to learn more about each error.搜索关键字以了解有关每个错误的更多信息。

this is the error i face while running it这是我在运行它时遇到的错误

try to fix the import : import React,{useState} from "react";尝试修复导入: import React,{useState} from "react";

plus check the export method in Body component加上检查 Body 组件中的导出方法

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

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