Why I left React for Vue
blog.sourcerer.io
blog.sourcerer.io
Everything else is biased and mostly wrong. In terms of performance, recent versions of react with Fiber can achieve figures vue can only dream of.
The conditional in react is just pure JS. He could have written an if statement instead of the anti pattern use of && for a non Boolean expression. And arguing that the v-if followed by code in a string is simpler sounds dishonest to me. Or we don’t have the same frame of reference.
The main problem to me is that the author compares his experience with react in 2015 with his experience in Vue in 2018.
And the numbers in that table are close enough to be meaningless anyways
And yes, Fiber is gonna be the bees knees
Who cares? You still write a JS conditional in the v-if string, right?
Instead of v-if="currentUser && currentUser.id && ..." you can just write v-if="canDoStuff(currentUser)"
Me. As a CTO I am not confortable having significant amounts of code embedded in strings inside html attributes. Also we use Flow / Typescript.
React is typesafe and sound. No templates, no strings, just functions. This is the basis of the pyramids of developer's needs.
Apparently not though, thousands of people use Angular, even more people use VueJS now.
Animals*. Not people, FTFY.
Joke aside though, I think this is an artifact of old school web development, which was a mess. People didn’t mind these kinds of hacks. But the number of people willing to accept such incongruities is going to go down in the next years as web development has now normalized into more sane practices that are standard in the software development world.
with Vue I am writing ..Vue which does not feel right coming from a heavy Javascript background.
My bias is that I've written a ton of embedded Javascript(old Spidermonkey) for embedded devices.
I hear that Vue is more popular for those who have less JS experience.
Everything started with "Start with your webpack file" and I wanted to just swear off front end forever.
So vue was a breath of fresh air at the time. Then I started at a company where react was the norm and I can't imagine going back to vue at this point.
However I must admit, the css story within vue is more interesting than React and its collection of CSS-IN-JS libraries.
if (unreadMessages.length > 0) { addComponent(this) }CSS-in-JS is one of my favorite parts of the React ecosystem. Style as a function of state is such a natural extension to React's programming model that I end up cringing a bit every time I have to go back to writing a bunch of different classes and applying them conditionally. Representing styles as data also means you have the full power of JavaScript at your disposal to compose and manipulate styles (not to mention access to a proper module system), whereas with plain CSS you're limited to a handful of mixins offered by whatever post-processor you choose, and those in turn are generally limited in terms of expressiveness themselves by nature of only being able to perform simple string interpolations, since that's the format they have to deal with.
I think these benefits are analogous to the benefits of HTML-in-JS a la JSX over traditional JS-in-HTML templates. I'm honestly struggling to see why someone would prefer HTML-in-JS but not CSS-in-JS.
That is, all of these frameworks are underpinned by a certain awfulness that is born of the impedance mismatch between applications vs Web. The right framework would abstract away CSS, templating, HTML, and all of the other awful that we've unfortunately come to accept as the cost of doing business when building Webapps.
So far as I know, that framework doesn't exist yet.
Pretty much all of the UI frameworks on any platform that I personally know of use some combination of an XML-based templating system for laying out components and a programming language to implement the logic behind those components, which is fairly analogous to how the web has HTML for templating and JS for implementing logic. Perhaps the impedance mismatch you're talking about lies in how the web handles styling, i.e. CSS itself and how it's not integrated into either the templating or the logic side like certain other frameworks but is rather a separate independent piece altogether?
Just trying to understand where you're coming from, because in my view React itself _is_ already a powerful abstraction over the DOM (in React you write components, and rendering those components to the DOM is an implementation detail involving an entirely separate library, react-dom, which can be seamlessly swapped with libraries dealing with the implementation detail of rendering to other targets like react-native, react-canvas, react-sketchapp, etc), and CSS-in-JS in the React ecosystem is itself a powerful abstraction over CSS for implementing styling as a function of state (though this abstraction hasn't yet been taken advantage of quite as much, the only notable exception I know of being glamorous-native, which implements glamorous's style as a function of state pattern on top of react-native's Stylesheet primitive rather than on top of CSS).
>all of the UI frameworks on any platform that I personally know of use some combination of an XML-based templating system
I also know of no other approaches with significant traction. That's the problem I'm referencing: they all take the approach of starting with technology that was designed for serving static documents then, essentially, layering on some cruft that attempts to adapt it for dynamic environments. This is obviously because the delivery platform (browsers) still rely on the underlying tech. But, there's no reason this can't be completely abstracted away by our tooling/frameworks.
I understand your references to React's abstraction but, in the end, it still comes down to CSS-in-JS, HTML-ish templating, etc. So, React's is not really an abstraction "where it counts". Think about it: why are we writing CSS at all when what we want is an application? In other words, if there were no Web and you wanted to build out a platform and/or development ecosystem for constructing applications from scratch, would CSS or XML-based templates, etc. be a design-choice you'd make? Of course not. They are wonky and inefficient for these purposes. Meanwhile, we're at the point where pre-compiling on these frameworks. So, why isn't there a framework that looks more like what we'd build from scratch that then compiles down to the Web-ish stuff we're working in (i.e. JSX or similar); thus completely abstracting away everything Web?
Because if you step back and look at, say, JSX through this lens, it's slightly insane. Not picking on React here--just following up on your example. This problem is endemic to virtually all frameworks that have gained significant traction.
There's a better way and it's frankly probably more akin to Swing or Visual Basic than it is to anything we've seen thus far.
The whole v-if statement versus JSX is rather superficial imo. Personally I don't like awkward DSLs that depend on code inside a string, but that aside, did the author ever wonder why JSX uses &&? JSX is fundamentally a fancy syntax over function composition. What's nice about this is that it's a more general abstraction than what Vue offers. Vue has to give the user all these v-if, v-for, v-whatever directives, while React just gives two tools: function composition and brackets to return an expression. You could argue that this is more tedious, more code to write, whatever, but it also means that you don't have to depend on your library writers to add more directives. That being said, I understand the joys of syntactic sugar and I guess v-if is kind of nice.
Binding is a JS problem not a React problem. The fact that these are confused leaves me even less credence in the author. If the author learned about the mess that is JS scoping, they'd understand why binding is necessary.
setState exists for a reason as well: state updates in React should be controlled and minimized when possible. I don't want my state in React to update like a normal JS object. In fact, I'd prefer if React moved to a ReasonReact style reducer format just to emphasize that state should be treated immutably.
All the "code is smaller in Vue" is extremely subjective. I'd need better examples than v-if to judge that. Plus, terseness comes at a cost. I can write extremely terse, metaprogrammed Ruby or even worse, Perl. Chances are I won't understand it within a month.
Finally, I see the author using the word "template" repeatedly. React is NOT templating. This is a very important point. Components are a far far more important abstraction than templating. Components can be wrappers that provide state, or a way of abstracting API calls, or a way to control routing. In the end, they're functions (or rather closures) that call other functions. Calling components "templates" betrays a fundamental misunderstanding of React's core principles.
This is going to be a huge problem going forward since the React documentation team seems to have made it their mission to try and obfuscate the details of JS away from their readers rather than educate them. Which is a terrible decision.
What people coming from a templating background often consider as "quirks" of JSX (such as the limitations around conditional branching and why properties need to be camelCase rather than kebab-case) become painfully self-evident after seeing how the equivalent JSX code would look like in the plain JS React.createElement form.
In fact, in my own projects I often prefer to import createElement, alias it as something short and use it directly to write rendering functions over using JSX because I find it removes a lot of the impedance mismatch involved with switching back and forth between JSX's psuedo html syntax and regular JS syntax in JSX expressions (and basically any other part of the codebase that's all written in JS). Plus, JSX syntax is actually generally _more_ verbose than the raw createElement calls when aliased due to things like requiring named closing tags for any component that takes children and needing to use `blah={blah}` over the `blah,` object property shorthand for passing through props.
Though in team settings I still resort to begrudgingly writing JSX because people are more familiar with it, and I'd probably have to pick a fight with every new team member to get them onboard with the idea, and I'd rather spend that political capital on less superficial issues.
I sometimes really wish the React folks never invented JSX, and just forced everyone to write createElement calls to begin with, then all of these points of confusion from people coming from templates could have been avoided (and we'd end up with only my preferred syntax as the one true way to write components, haha), but I do wonder if React would have taken off as it did if it didn't come with JSX to give people that sense of familiarity, even if it ends up causing much more undue confusion over the long term.
This year I picked up and started learning React after some experience with vanilla JS and jquery. I first tried Vue and for whatever reason, non-trivial examples were so hard to wrap my head around.
The documentation was hard to follow sometimes, and I had some issues with documentation on other projects like Nuxt.js, whereas the Create React App and Gatsby docs are so good.
I tried React just when I was about to swear off front end web development, and everything clicked. I've never felt like I had superpowers until I started using React to replace jquery soup.
Nowadays, I use vue occasionally if a project is using it, and it's easier to understand for me now. I still greatly prefer React, though, and JSX is a joy to use.
which still matters, even though nobody chooses to go that route, because in theory it allows beginners to learn the JSX abstraction seperately, and helps smooth out the learning curve. Unfortunately nobody actually seems to learn this way because there's so much emphasis on getting devs up to speed and working on production systems as quick as possible, at the expense of actually imparting them with any wisdom or knowledge. The React team are the worst at this (although Vue is a very close second), there's no good reason that I need to go to Dan Abramov's twitter and blog to find out how the library I'm using works. It should be in the official docs. Otherwise you're just training devs to code through rote memorisation of patterns instead of any actual knowledge or understanding.
I'm sympathetic to not reinventing the wheel when unnecessary, but on the flip side, I haven't found the vue templating syntax to be anything but intuitive and cognitively easy to predict. It's not like you're prolog all of a sudden.
Curious what this is about?
It probably helps that I’ve really been learning JS with TS after a decade of Python, and the TS community is pretty good in Reactiflux.
a couple other thoughts:
- the single file concept with Vue is awesome. But I find it irrelevant with JSX - and I never could get it fully working in my IDE (VSCode or VIM)
- the patterns seem to be more established in React (which is helpful to someone who’s learning and developing).
- the VueJS libraries that I used were often a reaction to a React library and seemed to be an afterthought, unfortunately.
All in all, I like having experience in both, but I don’t see a reason to go back to VueJS in the near future.
I looked at W3C web components instead and I liked the concept better. For example why not define control flow elements like, for example <c-if> or <c-loop>? However I didn't gain enough practical experience to be able to recommend them. Perhaps there are problems lurking behind them.
So this left me wondering why web components aren't as popular, even including accompanying frameworks like Polymer. I suspect that in a few years Vue will maybe again being overtaken by another framework basing on W3C web components, just because web components feel more natural than Vue components.
I'm now 100% on team VueJS.
You get stuff done quicker, the files contain templates and logic separately, and it makes me happier to work with VueJS. For those people preferring React over "muh its just js", please - it's just code, to get the job done. Use whatever gets the job done and makes you happy. After a few days of VueJS you'll find it incredibly nice to use.
Also I don't know anything about React's material design component set, but I know Vue's Vuetify is really well made, especially comparing to the equivalent in Angular.
1. Template syntax. While this is just my own preference, my Vue template is 20% shorter than JSX equivalent, mostly due to fewer brackets and better HTML's class support.
2. Computed property: this is so cool and efficient because computed properties are cached (equivalent to Mobx). We also have computed setter as well.
3. Built-in 2-way binding for inputs. Yes I know React people will condemn me to hell for this, but this has been a heaven for form-heavy application. This also makes the HTML you write much much shorter.
4. Prop mutation: this one is extremely controversial. Imagine this.props.foo = newFoo" in React (in Vue land it's "this.$emit('update:foo', newFoo)"). This is useful in situation where you want to mutate a parent's state without going to all the boilerplate of writing store/actions/dispatch. For example
<div>
{{ user.firstName + ' ' + user.lastName }}
<popup-update-user user.sync="user>
</popup-update-user>
</div>
By looking at the above code, I can tell that <popup-update-user> will take an object called "user" in, modify it (and probably calls an API), then update the user object back to me. Of course I can do all that in the Vuex store (or in your favourite Redux flavor, but imagine all the code that has to be written)5. Watch expression: it's beneficial and concise if you know what you're doing and not abusing it. This doesn't even exist in React. (edited: plain React doesn't have this, Mobx does)
6. Built-in Vuex support out of the box. Enough said.
7. Nuxt's offerings are superior to what Next can offer. Nuxt allows layout, param validation, node server middlewares, sass and Vuex integration, sensible configuration, and a system of plugins.
8. Filters: coming from functional languages that support pipeline operator, this has been dope to my eyes. Instead of writing:
{ formatDateTime(toDate(myDate), "DD-MM-YYYY") }
you can write it in a better way: {{ myDate | toDate | formatDateTime("DD-MM-YYYY") }}
Of course, the difference is just syntactic. But I hope in the future, Vue's filter can be cached just like computed properties.9. It doesn't need Babel. I dropped Vue into a legacy PHP Symphony project, wrote the Vue's template in a <script type="x/template"> and wrote the components in plain ES5 object, and it just works !!!
10. The event emitter is a better pattern than calling prop as a function.
<MyImageGallery onImageSelected={doStuff} />
vs <my-image-gallery @imageSelected="doStuff" />
Again, you may argue that this is syntactic sugar, but for me it's clear just at a glance which props are "in-ward", and which props are "out-ward"11. Vue doesn't intefere with SVG attributes. in React, I have to convert "xlink:href" to "xLinkHref", which is annoying
It is like shooting your future self in the foot.
On the other hand react make some things difficult because they are antipatterns, independently of react itself. (I'm looking at you number 4: Prop mutation...)
This is of course for CM0 type of whatever development though that may be in carriage of more advanced software life cycle systems. I tried some Vue dot js, I got some Angular dot js, I saw Angular dot whatever is difference positive. I read JS survey reports and of course always am super diligent about understanding Stack Overflow surveys of developers.
I think any particular perspective on the end results tends to be from the myopia of the skillist's perspective (to use confederal type of language instead of under-squiggley-tells-me federal non-adverbial BE that IBE can understand, without massive disassembly efforts on the part of the communication triangle (most direct, least direct, something else).
This is sort of like unpunctuated scriptures being upgrade to punctuated before being universalized after failed attempts to understand the Hegelian master/slave "golden" pretend morality (not to be hypercritical about "geeks" jargon file meaning as someone who knows chickens can be engineering to be pretty amazing and basically do a 50 yard dash in amazing pirouettes like dolphins released from old Navy, Pavlov sacristen-blasphemer, padawan of Orloff, yards that aren't still supposed to be around).
I mean it is Bacchanalia day and all, so Festivus!
React is great, Vue is great, conditional reflexology is trump over nonreflexive thinking attempts, it is all good to Pathology Excellent Rubbish Lister (PERL, red squiggle word kill count = 0). Ok front door 89 hz beep went off. I'm over my trolling limit. Be well, program in popular script-y.