When we return something in JSX, we could write:
<ul>
{Array.from({ length: 9 }).map((e, i) => (
<li>{i}</li>
))}
</ul>
or using an IIFE:
<ul>
{(function () {
const result = [];
for (let i = 0; i < 9; i++) {
result.push(<li>{i}</li>);
}
return result;
})()}
</ul>
Example: https://codesandbox.io/s/busy-aryabhata-egv27
But is it possible to write something like:
<ul>
{
const result = [];
for (let i = 0; i < 9; i++) {
result.push(<li>{i}</li>);
}
return result; // somehow "return" the array
}
</ul>
which is, just write plain code without an IIFE, and is able to somehow return the array we have created?