The problem IMO is that it's harder to read and write than:
<ul>
<li v-for="num in listItem">{{num}}</li>
</ul>
That's Vue's syntax, but any other templating language is more readable to me than JSX.The problem IMO is that it's harder to read and write than:
<ul>
<li v-for="num in listItem">{{num}}</li>
</ul>
That's Vue's syntax, but any other templating language is more readable to me than JSX.So many initial questions that just aren't there if you just use Javascript.
v-for="item in list"
if you need idx:
v-for="(item, i) in list"
pretty standard stuffs
When I'm trying to digest a bit of code, the superficial representation of what's present on the page is only half the battle - I also like to understand what it's doing under the hood. For me, then, JSX is way easier to grok than this bit of code, since I have a mental model of how JS works, and JSX is just a very small serving of syntactic sugar to compile an HTML like template into native JS. I know the transformations that are happening, and I can envision the code that it's being transformed into.
So is this really a problem?
Classic MVVM pattern
I don't understand how
<ul>
<li v-for="num in listItems">{{num}}</li>
</ul>
is less readable than <ul>
{listItems.map((num, i) => <li key={i}>{num}</li>)}
</ul>
Both are pretty readable, but the latter is essentially normal javascript, with the idea that you can return dom elements in it. The only thing that a javascript developer with zero jsx experience needs to know is that you can express dom elements within your javascript and treat them exactly like functions that return that element (which is what they are).What someone has to know to parse your vue example is the exact syntax for for loops in vue, evidently the syntax in this example is quite simple but what if they want to perform extra logic in that loop to modify which elements to show? In the react example all they have to do is know javascript.... in Vue they have to go look up how to do that in Vue.
return (
<ul>
{numbers.map((num, i) => (
<li key={i}>
{num}
</li>
))}
</ul>
)
Which with syntax highlighting is, imo, as readable as any piece of code.The advantage is that it is statically checkable with a linter, so you would get a compile-time error if you misspell the HTML tag, a variable or anything else.
If you use something Typescript, the compiler will even check the props given to components (and if you use VS Code, you'll get auto-completion for variables, methods, props and anything statically checkable). You can even apply inheritance to components for dynamic component switching.
I briefly used Vue before switching completely to React (with Typescript, Webpack and Mobx) and it finally became enjoyable to write Javascript applications.