I may have mixed between expression and statement, however in JSX {} must return exactly 1 expression, so that limits the amount of code you can place there.
Your'e missing the point arguing about semantics of components or JSX elements, the point is that if you want to avoid control flow via expressions, you must destruct you template (however simple it may be) into tiny template fragments that makes it harder to understand the complete rendered picture.
Imaging if JSX could look like this:
<div class="container">
My list
@for(item in list) {
<h2>{item.name}</h2>
@if(item.loading){
<p>Loading...</p>
} @else if (item.error) {
<p>Error loading item</p>
} @else {
<p>{item.description}</p>
}
}
</div>
This is much easier than the suggested JSX approach:
const renderItem = (item) => {
if(item.loading){
return <p>Loading...</p>
} else if (item.error) {
return <p>Error loading item</p>
}
return <p>{item.description}</p>
}
const renderList = (list) => {
return list.map(item => {
return <>
<h2>{item.name}</h2>
{renderItem(item)}
</>
})
}
return <div class="container">
My list
{renderList(list)}
</div>