Cohchi
Cohchi

Reputation: 563

Multiple conditions in return reactjs

I am creating a react project and I can not do multiple conditions when displaying My component has a state like this: {user valid: "ok" valid2: "ok" }

In the return () I would like to add a condition to display "OK" if valid or valid2 is equal to ok I tried something like this:

<p>
 {
   this.state.user.valid === "ok" || this.state.user.valid2 === "ok" ? "ok"
: "verify"
 }
</p>

But it does not work How to do this please?

thank you in advance

Upvotes: 1

Views: 26388

Answers (2)

rahul kumar
rahul kumar

Reputation: 21

{edit ? <component name /> : pedit ? <component name  />: <Default component name  />}

Upvotes: 2

McRist
McRist

Reputation: 1758

if valid or valid2 is equal to ok. You need to add parentheses.

<p>
 { (this.state.valid === "ok" || this.state.valid2 === "ok")? "ok" : "verify" }
</p>

Upvotes: 10

Related Questions