9 ms·
We moved away from React to Vue about 8 months ago and everyone on the team is a lot happier. First reason is we hate JSX. It forces you to write loops, condit
by pier25 9y ago
We moved away from React to Vue about 8 months ago and everyone on the team is a lot happier.
First reason is we hate JSX. It forces you to write loops, conditionals, etc, outside of the markup you are currently writing/reading. It's like writing shitty PHP code without templates. It also forces you to use a lot of boilerplate like bind(), Object.keys(), etc.
Another problem with React is that it only really solves one problem. There is no official React router and we hated using the unofficial react-router for a number of reasons. A lot of people end up using MobX too.
With Vue there is no need to resort to third parties for your essential blocks. It provides an official router and store called Vuex, which IMO blows Redux out of the water when combined with Vue's reactive data.
Vue docs are probably one of the best I've used. They provide technical docs, plus excellent narrative docs (guides) for all their projects (Vue, Router, Vuex, templates, etc).
I won't say that Vue is perfect, but we would never go back to React.
If you don't like Vue but want to get out of React, check out Marko, the UI library by Ebay. It's better in every way than Vue or React except that the community and ecosystem are almost non existent.
http://markojs.com/ http://markojs.com/
- TheCoelacanth 9y ago> It forces you to write loops, conditionals, etc, outside of the markup you are currently writing/reading. I don't get this complaint at all. Between map and ternary expressions, you can get both loops and conditionals in your markup, e.g. <div> {listOfThings.map(thing => thing.isX ? <X thing={thing} /> <Y thing={thing} /> )} </div>
- pier25 9y agoAnd you think that's easier to read and write compared to any templating language of the last 15 years? Btw you missed :
- donpinkus 9y agoIt's slightly less easy to read than <li ng-each={myList}>...</li> But it means you don't have to learn a library's HTML API. Or when you want to loop through myList, but exclude a few particular items... you know how to write that in JS, but have no idea what to do in the mark up language. You could create a filteredList, but it's often not ideal
- pier25 9y ago> Or when you want to loop through myList, but exclude a few particular items Easy, just create a computed property in Vue.
- yev 9y ago+1, Also as a side effect you will get a cleaner declaration of the filtered list (rather than making it a part of the rendering process, lol).
- ghusbands 9y agoYes, that's easy, but adding something to your model just because your view wants it rather seems like the cart driving the horse. If your view needs something that your model otherwise has no use for, then it does not belong in the model.
- chii 9y agoThere's no real clear cut line where you can say that a model had no 'use for' a certain field. If your point of view is that a model is meant for more than just doing the view, then yes, adding view only fields may pollute it for others (e.g., analytics). But if your model is meant to drive the view of the app, then the story is very different. And some times you can't even tell if the model is just there to drive the view our not, since requirements change often.
- tigershark 9y agoI cannot really understand how today mixing logic and presentation in JSX is considered a good thing. The first principle when writing complex systems should be to completely separate the logic from the presentation layer. Nowadays people seem happy with intermingled monstrosities like the one shown in the JSX code upstream.
- HeyImAlex 9y agoAll of the "logic" inside render is _presentational_ logic. What would be a better place for that to go?
- dwb 9y agoYes, by a long way.
- iammiles 9y agoI'm with you on this. JSX is quite a bit easier for me to reason about than the Angular-like expressions of Vue. But I am glad that there are viable alternatives available for those who don't feel the same way.
- luke3butler 9y agoBut you can use JSX with Vue if that's what you prefer. Vue passes everything down to render functions in the end anyways. React forces JSX use, so a lot of times the battle between Vue vs React seems to be Vue Templates vs JSX which never makes sense to me.
- djur 9y agoReact does not force JSX use. JSX just compiles down to React.createElement.
- beefsack 9y agoI feel React.createElement is so unergonomic it's not really an option to use directly. A lot of React supporters mention it when people criticise JSX, but I don't think it's a pragmatic alternative.
- djur 9y agoI know people who use React without JSX and it reads fine, as long as you assign React.createElement to a shorter alias. I like that you don't have the visual noise of closing elements. I think it's mostly a matter of taste (and how much you care about your HTML-generating code resembling HTML).
- breeny592 9y agoNot to mention that if a section of markup gets too big, you can break that down to it's own method that returns tiny snippets so you can have really simple methods that end up creating the more complex end result i.e. _renderXOrY = (thing) => { return thing.isX ? <X thing={thing} /> : <Y thing={thing} /> } //inside the render method <div> {listOfThings.map(thing => this._renderXOrY(thing))} </div> I personally prefer this because when creating the top level of a component, I largely don't care about the individual elements of a list, but rather am structuring how that list will be contained etc. And let's not discount then the value that JSX brings of being able to easily unit test that your conditional logic renders the correct output easily (Jest + Enzyme = easiest tests I've ever had to write, bar simple functional checks).
- timmy-turner 9y agoRight, being able to compose, test, structure and develop my HTML in the same way I'm doing it with my application code is for me the main Reason for never wanting to go back to anything that's based on classic string-like templating. The latter always felt as clunky as programming without a proper function abstraction.
- hunterxg 9y agoFor me it's quite the opposite. I find that so confusing when you look at html in JavaScript and don't know right away what the result will be. It's like were back in 2002 doing PHP.
- breeny592 9y agoDifferent strokes for different folks - my thought to that is pretty much that I don't really care what the result will be on the grand scheme, but more specifically isolated nodes and how they will interact with my model/data etc. Having the ability to see exactly what's in scope right next to the markup to me is invaluable - one of my biggest dislikes in templating languages is swapping between files that define the data in the scope and the template to use said data.
- meesterdude 9y ago> First reason is we hate JSX. It forces you to write loops, conditionals, etc, outside of the markup you are currently writing/reading. It's like writing shitty PHP code without templates. here here! This has been my experience as well
- dom0 9y ago*hear hear! ;)
- chias 9y agoIn fairness, it is entirely possible that the parent was correctly indicating the location of a salient / appreciated point in this discussion thread ;)
- schemathings 9y agohere-here document spotted in the wild
- thecrazyone 9y agoI'm not OP, but that's unlikely. This is general language construct and is used in the beginning. No one use "here here!" :D Just use ockham's razor, would you suppose he misspelt a general language construct or created a whole new one? :) I can end this post here, but I want to mention one more thing I'm reminded of: In Sherlock Holmes TV Series (don't remember the episode), a woman dies while writing "Rache" in her own blood. Other characters tell him that Rache is revenge in German. Sherlock posits that she was trying to write "Rachel", a much simpler (I mean with less assumptions) assumption to make in the context. "HN Pedantry" is rubbing off on me :D
- ubernetes 9y agoThe funny thing about "Rache" is in the original story it was the other way round. :)
- 9y ago
- jbreckmckye 9y agoI feel like JSX is the biggest failed promise of React. It's supposed to make the behavior of views transparent by building markup in plain JS. But what actually happens is you have to write noisy JavaScript that obfuscates your markup. Just look at any component that dynamically generates CSS classes. Template strings with ternaries? Another dependency for generating nice CSS class strings? Give me a break. JSX falters because JS is not terse enough. You end up with templates that have neither readable logic nor readable markup. And naturally, programmers being as lazy as they are, these templates become a holding bag for -every- concern.
- ng12 9y ago> It forces you to write loops, conditionals, etc, outside of the markup you are currently writing/reading What does this mean? I have a sneaking suspicion this is a symptom of poor separation of concerns.
- pier25 9y agoIt means that you can't loop where you actually need that loop and that makes reading and writing markup harder than it needs to be. https://facebook.github.io/react/docs/lists-and-keys.html https://facebook.github.io/react/docs/lists-and-keys.html Since JSX mixes logic and markup indistinguishably I'd say that's where the poor separation of concerns really is.
- peller 9y agoI'm not sure I follow. To use the basic example from the link, as opposed to this: const listItems = numbers.map((number) => <li>{number}</li> ); return ( <ul>{listItems}</ul> ); What's wrong with looping this way?: return ( <ul> {numbers.map((num, i) => <li key={i}>{num}</li>)} </ul> )
- pier25 9y ago> What's wrong with looping this way? The problem IMO is that it's harder to read and write than: <ul> <li v-for="num in listItem">{{num}}</li> </ul> That's Vue's syntax, but any other templating language is more readable to me than JSX.
- sergiotapia 9y agoI find the JSX loop infinitely easier to understand what's going on. It's a javascript map. With your Vue example, what is listItem? An array? Can it be an object? Does listItem need a special decorator for v-for to be able to loop through it? So many initial questions that just aren't there if you just use Javascript.
- gramstrong 9y ago> First reason is we hate JSX. It forces you to write loops, conditionals, etc, outside of the markup you are currently writing/reading. It's like writing shitty PHP code without templates. You could theoretically write some template components and "avoid" javascript altogether. I wonder if anyone has actually done that? JSX isn't perfect, but I find the dirty things about it can be mitigated by keeping your components small, and if that isn't possible then keeping the render function small by breaking it out into several functions that return pieces of your markup. Writing small functions is sound general programming advice, but it seems especially true with JSX/React.
- pier25 9y agoYes, there is a project called react-templates by Wix that does that. We used it, but once you start using libraries like that one or MobX, why even use React at all?
- gramstrong 9y ago>We used it, but once you start using libraries like that one or MobX, why even use React at all? Well, you've got a point. I can realistically see some developers preferring to piece-meal their front end solution though, or build just the parts they need themselves. I like Vue, but the API seems enormous. I get that a lot of people like that about it, though.
- pier25 9y agoPersonally I don't think Vue's API is that big. Most of the bread and butter stuff are learned in an afternoon. IMO the argument that React's API is really small is a fallacy since React is but a small piece in your project. You get nowhere without a router, local and global state management, transitions, etc. The other factor to consider after the learning curve is productivity. Vue has a pragmatic nature and in my personal experience I can get the job done faster. I think React is idealistic. http://objectivism101.com/Glossary/Idealism_Pragmatism.shtml http://objectivism101.com/Glossary/Idealism_Pragmatism.shtml
- 9y ago
- thomasDE 9y ago> It's like writing shitty PHP code without templates. For me, it's the other way around. I feel like you can still separate the logic and markup, but instead of the template engine syntax you can just JavaScript. From the top of my head, I can at least remember six template engines' syntax I've learned: Smarty (PHP), Mustache, Blade (PHP), EJS, Angular and another custom template engine. When I tried React I was so happy that I did not have to learn another template syntax as it all was just JavaScript. Another template engine syntax? No, thank you. I stick to React.
- Bahamut 9y agoTo be fair, JSX has its own idiosyncracies too for templating, such as className, htmlFor, and the obnoxious attribute name for dynamically inserted html. It is not immune to the criticism that it requires learning.
- PeckhamPouncer 9y ago> To be fair, JSX has its own idiosyncracies too for templating, such as className, htmlFor, those are the Javascript attribute names. > and the obnoxious attribute name for dynamically inserted html. Depends on your taste, but this is a plus for me, personally. > It is not immune to the criticism that it requires learning. It's takes maybe 10 minutes if you're already a little bit familiar with XML and know Javascript.
- brlewis 9y agoActually those idiosyncracies are React, not JSX. Using JSX with Mithril I've had no trouble using reserved words as attribute names. Dynamically inserted html in Mithril/JSX is just {m.trust(str)} Edit: I should also mention that Mithril comes with routing built in, as well as XHR utility and streams. I'm finding streams super useful for sophisticated state management.
- twhb 9y agoThose names have nothing to do with JSX or React, they're the actual properties you're setting. JS properties don't map 1:1 to HTML attributes: while for example the "src" attribute is controlled using the "src" property, the "for" attribute is controlled using the "htmlFor" property, and the "class" attribute with the "className" property. All React is doing is setting the properties you tell it to. (The reason for the name change is that old versions of JS couldn't use keywords - like "for" and "class" - as property names.)
- hesarenu 9y agoJsx is one of the best parts of react. No way I can go back string templates and it's own languages.
- pacomerh 9y agoHm? You can actually write loops and conditionals inside of the markup. And... why would you strictly want to do that?, you can write cleaner code by separating your logic/UI. This look more like a rant overall.
- pier25 9y agoUltimately you can, but your JSX code becomes more difficult to read and write. > you can write cleaner code by separating your logic/UI That's precisely the point of using a templating language: separation of concerns. JSX mixes producing markup with your component logic. > This look more like a rant overall. There is a difference between an opinion and a rant. I really won't debate whether Vue is superior to React, I'm just stating why I prefer it.
- ksec 9y agoWhat makes Marko better then all others in your opinion? Apart from speed which is the only thing I could gather on the Google. And why are there no interest? Because it is from Ebay? I mean look at the reply and no one even want to touch on it.
- pier25 9y agoMarko is faster and lighter. Also the syntax of single file components is more minimalistic than Vue, which is a good thing. I'd say there is no interest because the single file components are quite new, and before that the project was focused on being a really fast templating engine. https://github.com/marko-js/templating-benchmarks https://github.com/marko-js/templating-benchmarks Check this presentation about Marko, I found it illuminating. https://www.youtube.com/watch?v=i6eZA8Y_GgA https://www.youtube.com/watch?v=i6eZA8Y_GgA
- atom-morgan 9y agoThanks for sharing this. I'd never heard of Marko until you brought it up and it looks amazing so far.
- ramses0 9y agoI've been using marko for ~1yr now and don't work for eBay. 1) It's a templating language, not JS, not ternary operators, etc. Where this really makes sense is the following (probably valid marko). I _dare_ you to rewrite this simple search-results component in your FE framework or programming language of choice. Note how "state" is transferred in to a component .../components/my-component/index.marko ``` <await( results from component.resultsPromise(state.search) )> <ul if( state.search && results.length > 0 )> <li for( r in results )> <!-- the "a href" will be prevented in a single-page context --> <a href="${component.getLink(r)}" on-click('emitEvent_ResultClicked', r ) >${ r }</a> </li> </ul> <ul else> <li><i>no results</i></li> </ul> <await-placeholder>Loading...</await-placeholder> <await-timeout>Timed Out!</await-timeout> <await-error>Errored Out!</await-error> </await> ``` .../component/other-component/index.marko ``` <div> <my-component search="whatever user searches for" on-result-clicked('handleUserSelectedResult')/> </div> ``` 2) It's like PHP (mostly the good parts) ... there's only one negative I currently have with marko and that's the deprecation of "<var />" or "<scope />", as with "really large templates" (already an anti-pattern), the lack of scope can cause variable shadowing. 3) you can break out into "just javascript" at any point ... `$ var xyz = 1 + 2 * component.functionAbc( 123 )` and then use ${ xyz } right after. I personally prefer having `scope...` in my arsenal so I don't accidentally re-use `var xyz` but it's really rare if you make small components and keep an eye on your refactoring. 4) It is _designed_ for both "virtual dom" + "HTML streaming" ... virtual dom is what helps diff trees efficiently (client side), but HTML streaming is the real genius. Given a relatively declarative template (which is what marko deals with), marko will actually take your "foo.marko" and literally compiles it into: "make_a_tree(...)" or "make_a_string(...)" which runs on client or server respectively. Seriously. ``` $ mkdir foo && cd foo $ marko create xyz $ cd xyz $ npm start $ open http://127.0.0.1:8080/ http://127.0.0.1:8080/ ``` Follow along with the docs / tutorial and then humor me and run the following: ``` $ npm start $ curl -s http://127.0.0.1:8080 http://127.0.0.1:8080 | wc -c 5388 $ NODE_ENV=production npm start $ curl -s http://127.0.0.1:8080 http://127.0.0.1:8080 | wc -c 1678 ``` I've used angular 1.x, ember 1.x, a touch of react, and I'm most hopeful for marko, as I really see a way for an SPA to start up using the smallest-possible-html-bootstrap, marko to download after first paint, attach handlers, etc. and be "as active" but "as quickly as possible" ... harkening back to the "good old days" of PHP and JSP where the content rendered quickly ... mixed in with the "good days of today" where subsequent page renders don't just blank out the browser, but instead, efficiently load up only the changed portions (ie: the SPA / single page app / progressive experience). It's easy to do a "progressive" experience requires a 1MB download of JS before first paint. It's actually really cool to be able to render a 100kb page in only 100kb of network traffic, but also to have all your handlers / regular JS working from the remaining 900kb ready to work automatically _enhancing_ your page, but not to have to make any tradeoffs or think about it in order to do it.
- nikkwong 9y agoThe quality of ebay's website gives me a lot of hope for marko /s. Seriously though, if they're going to build this why not fix the UI on ebay itself? Is it just too large an application or are is an update just around the corner? Also the scroll jank on markojs' homepage doesn't make me feel extremely bullish about the framework.
- andrewstuart 9y agoI like JSX.
- stephenhuey 9y agoAurelia has a great router and many other things going for it as well.
- moo360 9y ago> First reason is we hate JSX. I feel like this is often the reason people dislike React, and it mostly comes out of a misunderstanding of JSX and es6 syntax and interaction. Why do I say this? Because I've yet to hear an argument that came after a statement like above which was actually true in any way. Most arguments that come after actually expose the fact that the author of the statement simply doesn't understand the syntax usually because they've never really bothered to try to use it and instead are simply turned off by something new in their code. > It forces you to write loops, conditionals, etc, outside of the markup you are currently writing/reading This is quite simply false, it doesn't force you to do any of these things. A lot of people seem to think it does which again comes from a misunderstanding of the syntax. You're quite able to either embed your logic into the JSX or not, whichever you prefer. I most often see people lean toward the former unless the logic in question is extremely complex in which case it could be argued it's best being removed from the markup anyway. But JSX itself does not force you either way. > It's like writing shitty PHP code without templates I simply don't see a viable comparison here at all. > It also forces you to use a lot of boilerplate like bind(), Object.keys(), etc. Again, this is simply untrue. In fact I'd argue that if you're using lots of .binds you're doing it wrong. .binds inside your render function are actually bad practice due to the fact that they mean you're adding overhead of creating new bound functions as each .bind returns a brand new function every time your render tree executes. The overhead of such is probably negligible, however it's still inefficient and cumbersome and thus is bad practice. As for Object.keys() - While I share your dislike of the overuse of this particular method, I'd love an example of where you think this is forced on you by JSX because for the life of me I can't think of one. > There is no official React router This I completely agree with, it is annoying, and I too am not a fan of react-router. However it's so easy to create your own routing setup and/or plug and play other lightweight ones that I don't usually think of it as a particular plus/minus point when comparing to frameworks like Vue.
- alexkoeh 9y agoOur team had the same thoughts on react-router. I'd suggest checking out https://github.com/kriasoft/universal-router https://github.com/kriasoft/universal-router. It uses the HTML5 History Library (https://github.com/ReactTraining/history https://github.com/ReactTraining/history) for navigation.
- phatbyte 9y ago> It's like writing shitty PHP code without templates. I don't think you or your team knows how React works or even PHP. > Another problem with React is that it only really solves one problem. You and your team hate React for the wrong reasons. You just simply don't know what React is in the first place. React is not a framework, is more like a view framework, it was never designed to solve routing, models, problems.