5 ms·
because react decided to return JSX like element syntax instead of being simply a function returning a dom element doesn't mean that this should be standardized
by aatd86 1y ago
because react decided to return JSX like element syntax instead of being simply a function returning a dom element doesn't mean that this should be standardized.
- 90s_dev 1y agoGiven <foo bar={qux}>bla</foo> React used to transform it into React.createElement("foo", { bar: qux }, "bla") Now it transforms it into import _jsx from "react/jsx-runtime"; _jsx("foo", { bar: qux }, "bla") My proposal transforms it into { [Symbol.for('jsx')]: 'foo', bar: qux, children: "bla" } It's self-contained and generic, doesn't rely on auto-imports or globals, and doesn't have key collisions. It's the only way I can imagine it ever being standardized.
- pwdisswordfishz 1y agoWhat does <foo children={qux}>bla</foo> do?
- 90s_dev 1y agoThis is a known ambiguity in JSX, to the point where TypeScript gives this error: > 'children' are specified twice. The attribute named 'children' will be overwritten. ts(2710)
- pwdisswordfishz 1y agoNo, that's an ambiguity in React. JSX defines only syntax.
- 90s_dev 1y agoTrue. Then can you suggest a standardized ECMAScript JSX proposal that doesn't turn this into a "children" key on an object? Would you just transform it into an array? ["foo", { bar: qux }, "baz"] ?
- WorldMaker 1y agoThat array does better match the current function parameters, so would be a simpler proposal to existing transpilers.
- 90s_dev 1y agoYeah it seems fine. I wouldn't be strongly opposed to it. Standardization of either is better than nothing.
- aatd86 1y agoIn my opinion, first sin of react is that createElement should be a method of a document at best. There are a few things missing but jsx is sugar that complicates things for me. Just teach people function composition. It's easier.
- afavour 1y agoThe argument to standardize it isn't really "because React does it", it's "because a ton of developers find it really useful". That seems kind of undeniable to me, even as someone that dislikes a lot of React.
- silverwind 1y agoYep, JSX is even supported in Vue and probably other tooling. This kind of adoption calls for standardization.
- 90s_dev 1y agoHe's right, guys.
- aatd86 1y agoI don't think that it is sound to incorporate a DSL that imitates html only approximately into a language. That should remain an external library at best. And that's irrespectively of my view on jsx, the latter which I find non ergonomic and confusing. That many people are being force fed it to the point of familiarity does not mean that it is the best DX. we went from (html + js> to html in js and js in html. Quite very confusing to me. Knotty (naughty) complexity pun intended. It's more akin to stockolm syndrom to not improve on the statu quo at this point.
- afavour 1y ago> It's more akin to stockolm syndrom to not improve on the statu quo at this point. Describing something very popular as “Stockholm syndrome” because you don’t like it isn’t logical at all. And it’s easy to say that but I think it's incumbent on you to propose something better if you do. "No, not JSX. Something better than that." ...but what?
- aatd86 1y agoI was far from the only one to not like it when it got introduced. As I have explained somewhere else, plain function and method composition is clearer in my humble opinion.
- nsonha 1y agoif it returned dom elements it should not be standardized either. JS is supposed to move forward with clean abstractions, not blindly inherit things from the web that happen to be convenient to some people.