Conditional logic: `Bool ? 'str' : ''` can be simplified to `Bool && 'str'`
kyleoliveiro opened this issue · 4 comments
kyleoliveiro commented
const message = 'hello friend';
const showMessage = true;
${showMessage
? html`The message is: ${message}`
: ''}
// The above is the same as:
${showMessage && html`The message is ${message}`}
motss commented
@kyleoliveiro Is this a question? This does not work as expected. It will returned undefined
if it evaluates to false
.
kyleoliveiro commented
@motss Whoops, was supposed to be a suggestion. But you're right. It returns false
if showMessage
evaluates to false
.
LarsDenBakker commented
@kyleoliveiro You might be right, I think lit-html doesn't render undefined so yours might be a shorter syntax
kyleoliveiro commented
I tested, but it renders out "false" if showMessage
evals to false
. Sorry for the confusion.