5 ms·
I don't want to write a bunch of markup next to my javascript.
by ocfx 13y ago
I don't want to write a bunch of markup next to my javascript.
- masklinn 13y agoIt's cool, you don't have to use JSX, you can just use the React.DOM functions. Or build a backend for whatever your preferred template system is, as long as the backend ends up creating nodes of React.DOM objects. Or you go with Om[0] and use EDN[1], Enlive-style[2] or hiccup-style[3] tempting. Now if you want to physically separate the view logic and the corresponding markup generation, that's more debatable: they're extremely strongly coupled (and in fairly small chunks ideally) so you often can't trivially change one without the other, and thus keeping them together makes logical sense. See Pete Hunt's presentation which lumpypua linked, it tries to make that point fairly nicely. [0] https://github.com/swannodette/om https://github.com/swannodette/om [1] https://github.com/edn-format/edn https://github.com/edn-format/edn [2] https://github.com/ckirkendall/kioo https://github.com/ckirkendall/kioo [3] https://github.com/r0man/sablono https://github.com/r0man/sablono
- squidsoup 13y agoJSX isn't markup - it's XML which translates to Reacts internal representation which looks something like: <div className='foo'>bar</div> --> React.DOM.div({ className: 'foo', children: 'bar' }) You don't have to use it - it's a convenience provided for designers (and arguably developers who have realised that templating provides a false separation of concerns). Om notably (https://github.com/swannodette/om https://github.com/swannodette/om) ignores it.
- nacs 13y ago"JSX isn't markup - it's [Extensible Markup Language]"?
- rakoo 13y agoJSX isn't markup, it's a compiler that transforms common HTML-like to custom React.DOM objects. From the doc [0]: > JSX transforms from an XML-like syntax into native JavaScript. [0] http://facebook.github.io/react/docs/jsx-in-depth.html http://facebook.github.io/react/docs/jsx-in-depth.html
- squidsoup 13y agoSorry, to be clearer, I meant it isn't HTML.
- lumpypua 13y agoYes, yes you do. Pete Hunt's talk introducing React makes a really persuasive argument that in large frontend applications, having something markup-esque along with your JS is the best way to reduce component coupling and increase cohesion. http://2013.jsconf.eu/speakers/pete-hunt-react-rethinking-best-practices.html http://2013.jsconf.eu/speakers/pete-hunt-react-rethinking-be...
- spicyj 13y agoSeparation of concerns is a good goal, and your reaction is popular with people first seeing React (including me, several months ago!). But consider that usually JS to control a view is inextricably linked to the underlying HTML and you need to modify both whenever making any change regardless -- since that's the case, you might as well combine all of the code and markup for the view in one place. Work to separate concerns, not programming languages.