Reputation: 1604
I am trying to put a conditional statement within a conditional statement (something i thought was simple) in my code.
What is want is if weekState
(boolean) is true, and bool
is true, show the first jsx element. If weekState
is true and bool
is false, show the second jsx element. If weekState
is false, return null
. Semms pretty simple, but im obviously missing something.
{ weekState ?
{ bool ?
<TableRow>
{take(weekListForAllAdvisorsOfState, 14)}
</TableRow>
:
<TableRow>
{take(weekListForAllAdvisorsOfState, 7)}
</TableRow>
}
: null
}
I have looked at this, and this which should have solved my issue, and makes me think theres a syntax error im not seeing.
Upvotes: 0
Views: 69
Reputation: 13662
There is a pair of unnecessary curly braces in the expression after ?
. Either remove them, or change them for parentheses ()
:
{weekState ? (
bool ? (
<TableRow>{take(weekListForAllAdvisorsOfState, 14)}</TableRow>
) : (
<TableRow>{take(weekListForAllAdvisorsOfState, 7)}</TableRow>
)
) : null}
Upvotes: 1
Reputation: 330
I think adding a Fragment should fix this:
{ weekState ?
<React.Fragment>
{ bool ?
<TableRow>
{take(weekListForAllAdvisorsOfState, 14)}
</TableRow>
:
<TableRow>
{take(weekListForAllAdvisorsOfState, 7)}
</TableRow>
}
</React.Fragment>
: null
}
Upvotes: 0