"If you're ever writing code like this, please reevaluate your career in software development."
That's a pretty nasty comment to make about anyone in this industry over a simple for loop.
That's a pretty nasty comment to make about anyone in this industry over a simple for loop.
To be more constructive, I believe an understanding of when to use the right tool for the right job is paramount to a good software developer. JSX nodes are suitable for representing UI components but certainly not control statements such as a for loop.
<div>
{for (var x=0;x<10;x++) {
<div/>
}}
<div>
Not a templated component like that. That said, I have created repeater components and the like before, largely because JSX is so friendly that more design-minded people can use it very easily.EDIT: turns out that doesn't actually work, ha. I've never written JSX that way.
<div>
{[0,1,2,3].map((i) => {
<div/>
}}
<div>
on the other hand... <ul>
{this.listItems(items)}
</ul>
Then, within a function implemented on the same component: listItems: function(items) {
items.map((item) => {
return <li>{item.name}</li>
});
}https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...