简体   繁体   中英

Expression expected with const at React JS component

Could you please help me with this?

What I want to do is check if the user is registered. If it is registered it should show the home url and if it is not registered it should show the registration url.

For that I see and check the saved data (isRegistered), if it equals to null is not registered and should show the /register url. But its not working.

In the next line I have an error

const [isReg, setIsReg] = useState(false);

And it gives me this error:

Expression expected.ts(1109)

const App: React.FC = () => (
  
  const [isReg, setIsReg] = useState<boolean>(false);
  
  if(getItem("isRegistered")==null){
    console.log(getItem("isRegistered"));
    useState(true);
  }
  else{
    useState(false);
  }

  <IonApp>
    <IonReactRouter>
    <IonSplitPane contentId="main" when="(min-width: 4096px)">
          <Menu />
      <IonRouterOutlet id="main">

        <Route path="/" render={() => isReg ? {Home} : {Registro}} />
        
        <Route path="/Favorites" component={Favoritos} exact={true}></Route>
     

      </IonRouterOutlet>
      </IonSplitPane>
    </IonReactRouter>
  </IonApp>
);

在此处输入图像描述

it should be

useEffect(() => {
    if(getItem("isRegistered")==null){
    console.log(getItem("isRegistered"));
    setIsReg(true);
  }
  else{
    setIsReg(false);
  }
}, [])

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