Reputation: 524
I'm unable to find proper syntax of the use of AND and OR using inside the component fragments. Lets say i have data which may return condition in strings
conditionOne
conditionTwo
conditionThree
I can use if statment like this
<React.Fragment>
{data.condition === 'conditionOne' ? <>Do This </> : <> Do Something Else </>}
<React.Fragment/>
But I want to find out the similar syntax to find, if all conditions meets Or one of the condition meets than Do Something Else
or Do This
.
Upvotes: 0
Views: 215
Reputation: 191058
You can do
['conditionOne', 'conditionTwo', 'conditionThree'].includes(data.condition)
this would replace the data.condition === 'conditionOne'
expression.
You can also store that array somewhere else or use a Set
.
A less maintainable approach would be to use the logical operators, but that can cause noise in the conditional ternary operation.
Upvotes: 1