atropa belladona
atropa belladona

Reputation: 524

How to use AND and OR statement inside the component while comparing in react component

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

Answers (1)

Daniel A. White
Daniel A. White

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

Related Questions