h("div", {}, [
h("p", {}, "this is easy"),
...list.map((l) => h("li", {}, l),
])
With this you automatically get loops, variable interpolation etc without having to invent a compiler and new syntax. Can someone help me understand? h("div", {}, [
h("p", {}, "this is easy"),
...list.map((l) => h("li", {}, l),
])
With this you automatically get loops, variable interpolation etc without having to invent a compiler and new syntax. Can someone help me understand? <div>
<p>this is easy</p>
{list.map((l) => <li>{l}</li>)}
</div>
> you automatically get loops, variable interpolation etc without having to invent a compiler and new syntaxTo be fair to JSX, you use regular loops, interpolation, etc without any different syntax (`{}` accepts a vanilla JS expression), you just obviously need the compiler step to de-sugar the element tags to `createElement` calls.
Anyway I prefer the html looking syntax if anything because it looks like the output on the page. That’s dependent on a project coding style that doesn’t unnecessarily wrap things in components, which for my company’s product I’ve set as a standard.
And that is what a lot of the pushback against React seems to come down to as well -- it is overkill for simple things. And it is. But different people doing different apps with different levels of complexity... all have different needs.
So it is not as simple as one having appeal over the other. They are different tools for different problems.
But to your point, JSX doesn’t really do much. Your h function is basically what React.creatElement does. Google “React without JSX” and you’ll see how it looks.
JSX is just syntactic sugar over React.creatElement. And that is what makes it so nice… there _are_ no special constructs for loops, or variables, or components. They are actual JavaScript loops, JavaScript variables, and JavaScript function.
It makes JSX easier to reason about than most templating languages.