2
const App = () =>{
    const condition1 = true
    const condition2 = false
    return (
        <div>
            {condition1 || condition2 && <h1>condition met</h1>}
        </div>
    )
}

The code above only cares about condition2, condition1 is ignored. is there a way I can use the OR operator in my jsx? Also I've tried looking through this https://reactjs.org/docs/conditional-rendering.html and I can't find what I'm looking for.

2
  • 5
    Do you want to group the OR?: (condition1 || condition2) && <h1>...</h1> Commented Jan 31, 2022 at 8:00
  • 1
    @NickParsons That's exactly what I was looking for. Thank you very much! Commented Jan 31, 2022 at 8:03

1 Answer 1

5

Maybe you forgot to put parentheses?

const App = () =>{
    const condition1 = true
    const condition2 = false
    return (
        <div>
            {(condition1 || condition2) && <h1>condition met</h1>}
        </div>
    )
}

Sign up to request clarification or add additional context in comments.

Comments

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.