4 ms·
In your first example, if invokeFunction() returns 0, the text "0" will be inserted into the page. 0 is falsey, so `0 && <p>Hi</p>` evaluates to 0, but 0 is a n
by csande17 7y ago
In your first example, if invokeFunction() returns 0, the text "0" will be inserted into the page. 0 is falsey, so `0 && <p>Hi</p>` evaluates to 0, but 0 is a number so React pastes it into the page contents.
React has footguns like this because JavaScript expressions were not designed to be used as a templating language.
- hombre_fatal 7y agoThinking your function returns a boolean when it returns an int seems like another issue entirely, like habitually depending on implicit conversion like "==". If that's a common issue for a team, maybe it's time to look into Typescript. Seems like a very minor reason to use a whole new DSL with a whole new set of warts for all of your templating.