Closed pstockley closed 6 years ago
The problem with your suggestion is that <component-to-render>
will be evaluated even if <some-condition>
is falsy, because <component-to-render>
is a function parameter. ...unlike the JavaScript "truthy" syntax, which will evaluate <component-to-render>
only if <some-condition>
is truthy.
The closest thing to JavaScript's truthy syntax we've come up with is the standard Java ?:
"expression if" statement. It is a bit longer than the equivalent JS truthy syntrax, but not that long at all. We just do:
<some-condition>? <component-to-render>: null
I suggest we just document the pattern in the README.md file.
In JSX you can do conditional rendering of components inline as follows:
Currently, you would need to move this code to a separate method e.g.
We should introduce a helper function to support this kind of conditional rendering inline e.g