4 ms·
I've been wondering recently if there could be a more generic JSX renderer that could be built into browser. <script type="jsx"> type thing. I think it could w
by parhamn 3y ago
I've been wondering recently if there could be a more generic JSX renderer that could be built into browser. <script type="jsx"> type thing.
I think it could work if it decoupled the reactivity layer and exported a "rerender me" hook that libraries like react/preact/vue/solid/etc could use to manage reactivity.
Because let's be real, `<ul render="@items: (name,index)` and `v-for` type things are terrible. JSX got a lot of things right. It's a pretty darn good marriage of HTML and javascript as far as syntax goes. Besides className, key and the curly syntax to drop into javascript, its pretty pure and straight forward.
- beebeepka 3y agobut what about those if us who prefer other template engines? vue/angular are better than jsx. Differences are minor, of course. But why should it be jsx?
- FlorianRappl 3y agoBecause JSX is essentially just JavaScript. However, this also opens the door to the question: What will then render / use the JSX element? After all, a JSX element is just a function call. What function is called how is the outcome of this function then rendered? You cannot compare Vue/Angular (frameworks) to JSX (syntax extension for JavaScript). As a fact you could write your templates in Vue or Angular using JSX.
- beebeepka 3y agoI am aware it's possible to use jsx with vue. It's trivial and can come in handy. It's just js until templating. To me, these differences barely matter because I can do all that stuff on my own without any frameworks in the first place. Both are fine. It doesn't have to be a war.
- troupo 3y agoDifferences are major. Vue's templating is a haphazard collection of elements that grew organically as the author(s) realised that more stuff needed to be added for templating to work. There's the Javascript-like DSL, there's Javascript expressions, there are HTML-like attributes, there are HTML-like attributes with magical extensions, there are... JSX is trivially converted to a Javascript function call which immediately explains everything about its capabilities and syntax.
- beebeepka 3y agoBoth template engines have to provide roughly the same be because the output is simple render functions that emit html. Sure, they are different but map to the same browser apis, so not that different. I don't see how jsx is more trivial than html which is what cue templates are.
- troupo 3y agoVue templates are arguably much more removed from HTML than JSX (which doesn't map to HTML but to Javascript function calls). This goes into more details: https://news.ycombinator.com/item?id=19199423 https://news.ycombinator.com/item?id=19199423
- orangepanda 3y agoHave you looked at ECMAScript for XML (E4X) ?
- 20after4 3y agoI liked E4X a lot. It's really similar to JSX. Really too bad it was deprecated.
- uallo 3y ago> I've been wondering recently if there could be a more generic JSX renderer that could be built into browser. https://es.discourse.group/t/proposal-esx-as-core-js-feature/1511 https://es.discourse.group/t/proposal-esx-as-core-js-feature...