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?
Actually this is a bad practice, avoid nested ternary... but your code will be like this:
return (
<div id="App">
{ loading ? <Loading/> : (userIsLoggedIn ? <Redirect to="/login"/> :<Redirect to="/dashboard"/>)}
</div>
);