4 ms·
Ask HN: Why can't JSX be added to the language?
JSX is such a nice abstraction to work with. Why why why why why why why why why can't we make it part of the language
- acemarke 6y agoFunny you should ask that. Someone asked that exact question in Reactiflux a couple days ago. This was my response: > Many reasons. For one, anything that the browser supports now, it has to support... forever. For another, all browsers up until now don't support JSX syntax, so you'd still have to compile your code to handle all existing browsers. > Also, the JSX syntax is not React-specific. Typical usage is to compile `<MyComponent>` to `React.createElement(MyComponent)`, but you can edit your build settings to compile it to other similar APIs for other frameworks. > The JSX syntax has been pretty stable for a while, but there's been plenty of proposals to tweak it further. How would that get handled?
- osdevisnot 6y agoI guess your reasoning makes sense, but obviously there are counter arguments: > Compiling for older browsers seems ok. If we stop additions for this reason, we would essentially stagnate the whole ecosystem. > Sure, JSX is not react specific. No arguments here, but we should be able to come up with some convention - maybe `h` function? maybe the jsx pragma comment? > We've made sense of much more complicated mutually conflicting standards problems before... we just declare stuff to not work anymore... like marquee tag... and if it does not make sense sometime, we put in feature flags, or `use jsx` language pragma? maybe `use jsx 1.0`, `use jsx 2.0` ?
- duskwuff 6y agoMozilla actually had something similar to JSX at one point: https://developer.mozilla.org/en-US/docs/Archive/Web/E4X https://developer.mozilla.org/en-US/docs/Archive/Web/E4X
- osdevisnot 6y agoJSX sure has some overlap with E4X, however, JSX has no relation to the E4X specification: https://facebook.github.io/jsx/#prior-art https://facebook.github.io/jsx/#prior-art