简体   繁体   中英

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

export 'default' (imported as 'Body') was not found in './components/Body' (module has no exports)

ERROR

[eslint] src\components\Body.js Line 8:33: React Hook "useState" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function 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";

plus check the export method in Body component

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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