You don't have to. The beauty of it being a simple JS function is you have flexibility.
function FileList() {
if (!files.length) {
return <EmptyMessage/>;
}
return <List items={files} />;
}
function FileList() {
return files.length
? <List items={files}/>
: <EmptyMessage/>;
}
What feels unnatural is the syntax that these templates pull out of thin air to do things the language can already do. Why should I need to learn another syntax just for templates?
<div>
{items.length === 0 &&
<p>No items.</p>
}
{items.length === 1 &&
<p>Warning: You only have 1 item, at least 2 is required</p>
}
{items.map(...)}
</div>
`false` is not rendered by react, so this code is perfectly fine.
You don't have to, you can create a simple 1 line component to turn it into a declarative style.
It's the benefit of having a full language instead of a template DSL for rendering. Declarative syntax is easy inside of an imperative flow, doing the opposite tends to lead to problems though.
Ok, I should probably edit my comment to "JSX/TSX feels so incredibly natural except for needing to use JS ternaries for conditional rendering" because seriously what were they thinking there?