I'm writing JS with React and I have a part that isn't showing. I used {true (false &&…
Jump to turn (8)
- 1I'm writing JS with React and I have a part that isn't showing. I used {true ||
- 2But didn't you just say it was truthy, so why doesn't it show
- 3I realized that we needed to add an extra parenthesis to make it work
- 4So why did the previous one not work?
- 5But that doesn't make any sense. In React, we can use conditional rendering whic
- 6So you mean to say that putting || makes it evaluate to true instead of acting a
- 7I still don't understand. You just said that the expression before && has to be
- 8But it didn't actually render until I used an extra parenthesis.
- User
I'm writing JS with React and I have a part that isn't showing. I used {true || (false && false) && *insert component here*} and the component isn't showing
- Assistant
The issue you're facing is due to the logical operator used in the JSX expression. The expression
true || (false && false)always evaluates totrue, which makes the whole expressiontrue && *insert component here*evaluate totrueand the component isn't shown.To make the component show, you should remove the logical operators or change them in a way that the expression evaluates to a truthy value. For example, you could simply return the component without wrapping it in any logical expressions:
lua{ *insert component here* } - User