1

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

3
  • Is this a return from render method? Commented Aug 18, 2018 at 16:59
  • Hav you tried parentheses around the condition of the ternary operator? Like (this.state.user.valid === "ok" || this.state.user.valid2 === "ok") ? "Ok" : "verify" Commented Aug 18, 2018 at 17:03
  • Yes that’s it ! Commented Aug 18, 2018 at 17:45

2 Answers 2

10

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>
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

I doubt that this helps - or even works at all. To convince me otherwise please add an explanation of how this works and why it is supposed to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.