简体   繁体   English

在 React JS 组件中使用 const 预期的表达式

[英]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.如果已注册,则应显示主页 url,如果未注册,则应显示注册 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.为此,我查看并检查保存的数据(isRegistered),如果它等于 null 未注册,应显示 /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)表达式预期.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);
  }
}, [])

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

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