Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
);

enter image description here

like image 741
JAOdev Avatar asked Dec 21 '25 18:12

JAOdev


1 Answers

it should be

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

like image 112
FireFighter Avatar answered Dec 24 '25 08:12

FireFighter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!