5 ms·
> JSX is a gotcha-riddled kludge to clumsily shoehorn HTML into a JavaScript function return. Oh boy, now that’s some flame-bait. I don’t like JSX, and like th
by Semaphor 4y ago
> JSX is a gotcha-riddled kludge to clumsily shoehorn HTML into a JavaScript function return.
Oh boy, now that’s some flame-bait. I don’t like JSX, and like the Author also prefer Vue over React, but I know a lot of people simply dislike other frameworks *because* they don’t have JSX (or, as is the case with Vue, it’s theoretically possible but no one uses it).
- nicoburns 4y ago> I know a lot of people simply dislike other frameworks because they don’t have JSX (or, as is the case with Vue, it’s theoretically possible but no one uses it). Count me in that camp. My take is that while JSX isn't perfect, it's less of a cludge (and much more flexible because it compiles down to JS) than the templating languages that other frameworks use. I'd love it if they'd add just a little bit more sugar to JSX though. Support for JS-style comments would be top of my list.
- solardev 4y ago{/* I would be so happy to never have to do this again */}
- stickfigure 4y agoDoesn't every editor have a "comment" hotkey? I can't remember the last time I typed block comment characters in any language. cmd-/ in IntelliJ.
- solardev 4y agoI don't want to make the whole line a comment. I just wanna add a comment where the language don't want me to.
- stickfigure 4y agoSelect the fragment you want to comment out, then hit cmd-/. It doesn't have to be a whole line.
- nicoburns 4y agoMine doesn’t work very well in JSX blocks. Partly because I don’t think there is any way to insert a comment inside a JSX tag (to comment out an attribute).
- ncphillips 4y agoIt is possible: <Button // id=“commented-out” onClick={doSomething} />
- spiffytech 4y agoThe great part about JSX is some random new framework doesn't need a VS Code plugin to get syntax highlighting, and type checking Just Works. I can accept a template language for a major framework where I can count on decent developer tooling, but it's a hard turn-off when evaluating niche frameworks.
- Semaphor 4y agoHuh, that’s a pretty good point I never thought about. It’s not relevant to me personally, but having such a standard is certainly helpful.
- robertlagrant 4y agoJSX semantics are tied to React, aren't they?
- sph 4y agoMaybe I haven't tried hard enough, but it was a pain doing JSX/Typescript with mithril. All the TSX tooling expects a React API and if you use something else you get a ton of annoying type errors.
- WorldMaker 4y agoI used TSX with Cycle.js for a while and didn't experience too much trouble. Typescript has some simple compiler options to change how it generates JSX or JS and doesn't bundle any types out of the box for TSX: all of the React API types come from React's type library. Sometimes that was more of detriment than if there were base types in TSX because reimplementing mostly the same set of standard HTML elements and HTML-like attributes a third time in a different .d.ts file when switching VirtualDOM implementations was a chore. (It was fine, but it was a chore.) If you are seeing errors that are React specific, most likely means you just need a subtle tweak in your tsconfig.json.
- spiffytech 4y agoNot necessarily - bunch of languages have adopted JSX with slightly or substantially different component semantics from React (for example Vue, Solid, Forgo, Crank). A Crank component (which is an async generator) feels very different from a React component. Likewise for a Forgo component, which uses closures for state and doesn't have automatic rerenders. Solid doesn't have components in the traditional sense at all. Although the syntax they use for representing HTML is the same, the rest of the framework can have arbitrary design.
- linkgoron 4y agoYep, I've recently used Vue instead of React and I hate the magical templating system. Slots, magical rules for variable scoping etc. The templating is IMO way worse than JSX. I don't care for React one bit, but IMO JSX is the highlight of React. Everything else in React is pretty much just OK at best (and some not even that), and the development of React itself has been extremely slow with very relevant few features.
- bayesian_horse 4y agoJSX is more than tolerable if you use React as intended. You're not supposed to write single components that span a thousand lines of code nesting pure javascript and JSX elements. Even better if you can factor out any computation out of the JSX parts into selectors.
- ncphillips 4y ago+1 As someone who never runs into problems with JSX, I have definitely wondered if the criticisms against JSX/React are from people trying to use it in ways that are explicitly counter to its core philosophy.