vendredi 26 novembre 2021

Is it possbile to have an if insinde an if in return? | ReactJS

Im new to ReactJS and i'm wondering if it's possible to have an if statement inside an if statement in a return.

I am aware of the following syntax:

return (
  <div>
    { myVar ? <Component/> : <AnotherComponent/> }
  </div>
)

What i want is something like this:

return (
<div id="App">
  { loading ? 
    <Loading/>
      :
      userIsLoggedIn ?
        <Redirect to="/login"/>
          :
        <Redirect to="/dashboard"/>      
  }
</div>
)

Is this possible? If not, how can i achieve this?

Aucun commentaire:

Enregistrer un commentaire