Home > other >  How to condtionally check two condtions within a JSX expression?
How to condtionally check two condtions within a JSX expression?

Time:12-31

I am trying to test the validity of two condtions within a jsx expression within react. However, when I add my second expression to check for, I don't get an expected result. Rather, recieve the result of the expression as a 0 or 1 value.

This is my Current JSX:

{expression1 && (
  <button>Click me!</button>
)}

This is what I want, but this does not render correctly.

{expression1 & expression2  && (
  <button>Click me!</button>
)}

There must be a proper way to fix this. I am thinking that this is a syntactical issue.

CodePudding user response:

You seem to have forgotten to use the double ampersand operator:

{expression1 && expression2 && (
  <button>Click me!</button>
)}
  • Related