Vue.js vs. React
vuejs.org
vuejs.org
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.
here here! This has been my experience as well
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
And HTML string template languages have been shown to have numerous shortcomings at scale.
SoC comes from MV* architectural patterns. In real world front end applications, people who separate based on the file extension often end up creating JS files that breach SoC - they are both handling view rendering as well as application logic inside a JS file.
If there is something that should be conditionally rendered, using JSX is no different to a template language - only thing is the variable you're using to do that isn't actually in that file either (so, over-separation of concerns?). Both of these are logic - one handles it inline and the other handles it across multiple files.
No one is advocating that JSX should break SoC (a component should never talk to an API, or implement business logic - it should be responsible for given a set of inputs, it will render the same output time and time again).
What does this mean? I have a sneaking suspicion this is a symptom of poor separation of concerns.
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.
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>
)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.So many initial questions that just aren't there if you just use Javascript.
v-for="item in list"
if you need idx:
v-for="(item, i) in list"
pretty standard stuffs
So is this really a problem?
Classic MVVM pattern
When I'm trying to digest a bit of code, the superficial representation of what's present on the page is only half the battle - I also like to understand what it's doing under the hood. For me, then, JSX is way easier to grok than this bit of code, since I have a mental model of how JS works, and JSX is just a very small serving of syntactic sugar to compile an HTML like template into native JS. I know the transformations that are happening, and I can envision the code that it's being transformed into.
I don't understand how
<ul>
<li v-for="num in listItems">{{num}}</li>
</ul>
is less readable than <ul>
{listItems.map((num, i) => <li key={i}>{num}</li>)}
</ul>
Both are pretty readable, but the latter is essentially normal javascript, with the idea that you can return dom elements in it. The only thing that a javascript developer with zero jsx experience needs to know is that you can express dom elements within your javascript and treat them exactly like functions that return that element (which is what they are).What someone has to know to parse your vue example is the exact syntax for for loops in vue, evidently the syntax in this example is quite simple but what if they want to perform extra logic in that loop to modify which elements to show? In the react example all they have to do is know javascript.... in Vue they have to go look up how to do that in Vue.
return (
<ul>
{numbers.map((num, i) => (
<li key={i}>
{num}
</li>
))}
</ul>
)
Which with syntax highlighting is, imo, as readable as any piece of code.The advantage is that it is statically checkable with a linter, so you would get a compile-time error if you misspell the HTML tag, a variable or anything else.
If you use something Typescript, the compiler will even check the props given to components (and if you use VS Code, you'll get auto-completion for variables, methods, props and anything statically checkable). You can even apply inheritance to components for dynamic component switching.
I briefly used Vue before switching completely to React (with Typescript, Webpack and Mobx) and it finally became enjoyable to write Javascript applications.
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.
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.
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
You can go through the entire docs in less than an hour and get down to business. I did not have this experience with Angular 1 (don't know about v2) or React.
I just feel JSX is too awkward and verbose to be pleasant working.
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.
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.
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.
(The reason for the name change is that old versions of JS couldn't use keywords - like "for" and "class" - as property names.)
Granted, there is still some syntax you need to learn for JSX, but it's very little. If you already know HTML's syntax, the only new things I can think of are the curly braces for using JS expressions as prop values (you also need to know what a JS expression is, lest you try to use an if statement), and spread attributes.
All JSX is doing is transforming `<div className="foo">` into `[create div element]; div.className = "foo";`. If you wrote `<div class="foo">`, JSX would faithfully transform it into `[create div element]; div.class = "foo";` - which doesn't work.
React defines `React.createElement`, `<div class="foo"/>` transforms to `React.createElement("div", { "class": "foo" })`, so React could convert that under the hood to set className correctly.
Preact does something similar to allow this. However it now seems it is now too late for React for too little benefit. And there's a downside [1]:
> The JSX transform used to do that, but we don't recommend it because it's confusing if you ever try to pass class= or for= as a prop to your own components – you wouldn't expect to access them with a different name.
[1] https://github.com/facebook/react/issues/4433#issuecomment-1...
many years later, the workarounds like class -> className were designed by whatever party exerted most control over the JS DOM API (which is not really part of "Javascript itself") at the time, and who also brought you inconsistent camelcasing such as "onclick" ...
it's neither quite "native", nor is "defined by the same standards bodies" much of a sign of good design or worthy of copying.
feels more like if someone were to build, say, a modern high perf numerical library that includes necessary workarounds tributed to the eax/ax/ah/al peculiarities of x86 assembly.
mistakes were made. then copied, repeated and finally, standardised :)
h('ul', [ h('li', 'one'), h('li', 'two') ])
And use native array methods instead of v-for v-if and filtering data with component methods
This is even worse as for me. Generally the JSX/React.createElement approach itself and the fact that many people like the idea make me cry. Do people like it just because it's given by FB?
Sometimes it might be useful, for small components,something like
render: this.menu.sort().map(item=>h('li', item.title))
But i am using Vue with Pug and Stylus, i am fine with it.Why? Because tooling. Anything that's in JavaScript can be linted with ESLint, can be typed with Flow or TypeScript, is subject to dead code elimination by my minifier, can be shared via ES6 Modules/CommonJS wihin my project or NPM with no magic. All editors that understand JavaScript will give me all of their shinies (eg: tell me if I screwed up a conditional) without needing special framework specific support.
JSX itself used to cause these problems too (but createElement and the factories of old did not), but now that they're pervasive and that anything that supports ES6 supports JSX, I get all of these benefits for free.
The moment I hop into template/DSL land, I either hope there's a plugin with all the same benefits (often there is not), or I'm sad.
Note that people who use React + JSX and make stuff like "if" or "else" components fall into these problems too, so those have to be fully avoided.
TBH, in 2017, I'm not sure why we're still hand-generating HTML with any template language.
Instead, I'd really like to see a framework that gets away from the idea of HTML templating altogether and presents a true component/properties model on top of a canvas with flexible, property-driven layout options.
I think the intense UI-demands of progressiveness/SPAs expose the unsuitability of HTML for the task. But, simply because HTML is what we're stuck with browser-wise, there's no reason we have to think or work in HTML. Use tooling to abstract it away altogether and let a translator generate it.
When I last gave it a try I had to manually generated the HTML document but without a (at least of of the box) syntax like jsx. If I recall correctly graphics is still there, but it's mainly used for games
It has a clean-slate design, and there's a ton of buzz in the Elm community about it. :)
[0] http://package.elm-lang.org/packages/mdgriffith/style-elemen...
Have you tried QT or Xamarin?
These are for desktop/mobile apps right? If so, yeah, there are other options as well.
Was thinking more something like this, but for SPAs.
We have a components+properties model, driven in Python, which gets translated to HTML+JS+CSS. We also have a visual editor, and abstractions over a bunch of the client-server stuff that's typically icky on the Web.
The challenge of such a system is that the web platform is so huge and sprawling, and constantly growing - and all of it's written in JS/HTML. So we've made the pragmatic choice to prioritise usability by non-web developers, and open an "escape hatch" for doing layout etc in HTML if you really need to. But most of our users don't need it, and we're constantly working to extend the boundary of what you can do with simple properties and components.
>the web platform is so huge and sprawling, and constantly growing
>we've made the pragmatic choice to prioritise usability by non-web developers, and open an "escape hatch
Makes sense. And totally worth the tradeoff for the developer if it helps me flip the 80/20 rule around. And, if the component model is extensible such that, when I do have to open the escape hatch, I can plug a resulting component back into the framework (lay it out and set properties in the visual editor, etc.), that might be even more optimal. Either way, I'd rather a framework do the heavy lifting and let me deal with the edge cases than me do all of the heavy lifting and plumbing, so that's a win.
>and all of it's written in JS/HTML
And, this is the part where I do have to scratch my head a little. I'm going to guess you've heard this question 4,321,257 times, but why not support JS? It is the lingua franca of the Web (as your quote acknowledges) for better or worse, and virtually all devs already know it. There's also a rich JS library ecosystem.
The idea that I have to pick up Python just to try it out introduces more friction. I'm guessing that might slow adoption with a huge percentage of your potential audience who might otherwise have the knowledge they need to jump right in.
Thrilled to hear it! If you do try it in more depth, please do drop me a line (email in my profile).
> why not support JS?
Two reasons:
1. Basically, the moment you use JS, any discipline or abstraction you were trying to introduce dissolves. People will reach in and use the DOM/combine it with other Web frameworks/what-have-you. And then you'll still need to know HTML and CSS and all these other pieces, as well as this new framework, and you've done the opposite of simplifying web development. This is the "Javascript Framework of the Week" failure mode.
2. Contrary to your assertion, "most devs" don't actually know JS. It's something people only learn because they're learning front-end web development, and it's difficult to learn it without the whole HTML/CSS/frameworks hairball. Python is much friendlier to, eg, data scientists or embedded programmers or back-end developers, who have every right to think they should be able to put together a web app without learning three new programming languages and two new frameworks.
(This is another way of putting what I said earlier about "prioritising usability for non-web devs".)
I see. Kind of a purist approach that eliminates all temptation by not offering the option to go there. Sound reasoning, as JS definitely has slippery-slope potential.
>People will reach in and use the DOM/combine it with other Web frameworks/what-have-you. And then you'll still need to know HTML and CSS
I'm probably too biased to make a call on this. I'm so wanting to be released from that madness that I'd fight tooth-and-nail not to descend back into it.
So, I look at it the other way around: My JS would be more disciplined (and there'd be les of it), as I'd be released from the need to use it so much for stuff like DOM handling. In my ideal world, I wouldn't even know there was a DOM or HTML or CSS. I'd just use JS in event handling and, perhaps, functionality that directly supports the same.
>"most devs" don't actually know JS...people only learn because they're learning front-end web development
That's what I intended--that most web devs know JS--as I was speaking in the context of web development.
But, I missed the emphasis on the "non-Web devs" portion of your statement. I do get that and applaud you for staying with your focus. The product has to have a market and an identity. OTOH, it feels so close for guys like me in the Web dev world who know there's a better way!
>please do drop me a line (email in my profile).
Will do. And will try to reserve any web-dev specific comments. :)
JSX is another templating language. One built on top of JavaScript rather than HTML.
> 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.
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.
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>Btw you missed :
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
Easy, just create a computed property in Vue.
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.
I don't really know JSX much and without a specific example this is pointless to discuss. But basically JSX is syntactic sugar over javascript. A ternary is just a "if" condition so I don't see where is the issue here. Are you really using a template language devoid of conditionals? Even mustache the "logic-less" template has a form of it.
> The XAML file, as the HTML layer, should be completely devoid of logic and should delegate the whole work to the underlying model
The role of the model is and has always been to handle /business/ logic not presentational logic. If you put your dirty presentational logic inside my models I can tell you I will /never never/ accept your pull request.
* You don't know JSX
* You have no idea of the specific example posted in this thread that I'm speaking of
* You have no idea about WPF and what is a view model
But nonetheless you feel entitled to discuss about things in which you have zero knowledge. This is the JSX code posted in this thread:
<div> {listOfThings.map(thing => thing.isX ? <X thing={thing} /> <Y thing={thing} /> )} </div>
Instead of this monstrosity in XAML would be like this: <ItemsControl ItemsSource={Binding ListOfThings} />
But of course for you is better the JSX code. Luckily for me you will never have to review any of my pull requests, I seriously doubt that you can accept something that you don't understand.
https://msdn.microsoft.com/en-us/library/system.windows.cont...
What is that if not an horribly verbose switch case for modifying the representation of different elements passed to the ItemsControl?
I am not advocating that the JSX is particularly pretty or clever. I am objecting to your crazy notion that there should be no logic in the representation layer.
<ItemsControl ItemsSource={Binding ListOfThings} />
If you are looking for exactly this feature you might be disappointed.
> Although not strictly associated with the MVVM pattern, Vue’s design was partly inspired by it. As a convention, we often use the variable vm (short for ViewModel) to refer to our Vue instance.
I am sure it wouldn't be very hard to develop such a layer within React if needed.
It gets really old to see people try failed experiments over and over again, which pretty much is what you are suggesting.
Also, you got some display logic in your examples there, buddy. If you can't see it then no wonder this conversation is going in a circle.
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.
_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).
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.
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.
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
Check this presentation about Marko, I found it illuminating.
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/ ```
Follow along with the docs / tutorial and then humor me and run the following:
``` $ npm start $ curl -s http://127.0.0.1:8080 | wc -c 5388
$ NODE_ENV=production npm start $ curl -s 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.
Marko is also the only framework that supports server-side rendering streaming. This means that your user will start to see HTML even before the page has finished rendering. Afterwards, the page is bootstrapped and components run on the client side. It's very fast.
Also the scroll jank on markojs' homepage doesn't make me feel extremely bullish about the framework.
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.
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.
https://npm-stat.com/charts.html?package=react&package=vue&p...
In reality, React is downloaded roughly 4-5x more than angular and 7-8x more than Vue. In August so far, React has 75% market share among these three libs. Interestingly, this share has grown in August compared to both last month (July) and beginning of year (January).
While this thread and the license thread might indicate that React is dying, it's not. It's growing.
If Vue is going to be what React is today, it has quite a long way to go.
It can be deceptive when you look at charts that list totals when what you're concerned with is growth rate.
A more accurate narrative would be that Vue is eating the dying Angular.
https://en.wikipedia.org/wiki/Usage_share_of_web_browsers#W3...
Which one do you use now?
I remember that when Larry Page granted the Founder's Award to Chrome, there were several TGIF questions saying "Isn't it premature? Chrome's market share is only 5%, and the vast majority of web users have barely even heard of it."
Larry's response was "In my mind, Chrome has already won," and in hindsight, this is probably what he was referring to. When a large number of users are flooding into a brand new product, even though there's already an alternative that's pretty good on the market and still growing, that usually means that the new product fills some burning need or deficiency that existing alternatives don't. That comparison will continue to hold unless competitors address it. That's why investors look so heavily at growth rates: if you're growing 15x faster than your competitors, you're probably going to end up with the whole market, given enough time.
I literally remember standing there listening a microsoft rep tell me that 'When you don't have much market share, there's always room for great growth".
...just saying, you can spin the story however you like, but the fact is that Vue currently has a reasonably insignificant market share.
Beyond that, all we can do is speculate.
Sound familiar? (and I assure you, that 3.6% is a whole lot more than a 135k measly installs a day).
:P
That's called 'unsustainable small scale growth'; and it's what you're seeing with vue right now.
A good year over year growth of 2 or 3% is far far far more compelling than a tiny 100% growth rate from nothing to nothing.
Look at chrome's history of growth and that's what you'll see. In fact, if you look at the long term history of all three, that's what you'll see with reacts growth as well: https://npm-stat.com/charts.html?package=react&package=vue&p...
Sure, maybe vue and windows phone are different beasts and they're difficult to compare... but the comparison to chrome makes zero sense either at this point.
This '100% growth' stuff is pure hand waving nonsense. Its obviously unsustainable.
The question is, can vue turn its current trend into a sustainable consistent growth and take on react? I dunno, but I can guarantee you the answer to that question is something that no one knows at this point.
That may not be a true leading indicator of adoption, but it is hard to argue it isn't an indicator of increased interest.
Edit: more information: https://github.com/babel/babel-standalone/blob/master/README...
It's /really/ not intended for use in prod.
.
Edit. I kinda sent off on a stream of conciseness about reactjs.net here, feel free to ignore this bit.... :D
Infact, as well made as it is and despite using reactjs.net heavily for the last couple of years, the only time i would be inclined to use it on a new app is to leverage the universal rendering, or if your react app is just freaking massive and takes forever to run a build - otherwise you may aswell just throw everything at webpack --watch via iisnode or regular 'ole vanilla node.
Then again we had to make a bunch of changes to the package itself to fully support our bundling (we don't like cassette so we made our own) and to support multiple server-side bundles, none of which are agnostic enough to warrant a PR, so upgrading reactjs.net to a more recent version is a hassle, making me slightly biased against using it ;)
<div id='root'></div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.38/browser.min.js'></script>
<script type='text/babel'>
const App = () => <div>Hello World</div>;
ReactDOM.render(<App />, document.getElementById('root'))
</script> elem.div(elem(Component, {prop: 'value'}), {className: 'foo'})
It's surprisingly common, and it's listed not too far down on the React installation page:Most devs I know start a react application by cloning some standard git repo which has a working webpack/tidyCSS/redux/some test suite etc. and then write your first line of useful code. The boilerplate is enormous!
As for build systems vs. script includes... I think Vue is probably being used in a lot more hobby projects than npm downloads would seem to indicate...but using a build system is a stronger indicator of a professional web app and pretty much necessary for any non-trivial project.
Otherwise we would all be still using PHP instead of Python or Ruby.
edit: looks like angular had 1 million downloads last month and @angular/core 1.7M.
I see React and Vue as tools for scratching very specific itches: fast DOM manipulations and databinding that actually works. React was this, then it grew and grew and grew. Vue is threatening to move away from this.
Also, still pissed that my year-and-a-half old react code is now hopelessly out of date, and requires updating (guess what, I'll be porting it to vue instead). That is bullshit.
If you want to use React with Rails, use Rails in API mode and keep the front-end separate. I'm not sure how rewriting in Vue is going to solve any of your problems at all.
"The browser loads scripts, why can't that be enough?"
Not sure what you mean by this. Whatever you use, the browser will be loading scripts.
Vue doesn't require nodejs to follow along with the examples
Vue doesn't prescribe to me how I should write my markup (beyond Angular-style attributes) or force me to violate separation-of-concerns.
Vue doesn't require it's stuff to be stored in $ROOT/app/assets/javascript/components, when all the rest of my code lives in $ROOT/app/whatever
Vue doesn't (or didn't) prescribe all these stupid little companion addons to do things I learned how to do (and do better) years ago
Vue doesn't give me a shitty markup language (JSX -- class vs className? Fuck off!) or even worse alternatives (its super verbose JS-DOM alternative) if I don't want (or can't) use it
Vue doesn't have nearly as large of an obnoxious, inexperienced, harebrained, and cloud-huffing crowd that will argue with me when I express distaste in it
Personal insults aren't cool.
I grabbed a point around the middle and one near the end. React: 642K > 1,184K. Vue: 53K > 155K
https://www.hntrends.com/2017/july.html?compare1=React&compa...
Hiring is a lagging indicator, but I see React hitting a plateau the way angular did. I see Vue is on the cusp of takeoff. Time will tell if it fails to launch, but I'm seeing more interest in Vue at meetups than React.
I think a lot of this has more to do with React's state management than licensing. One of the react developers said it best. Paraphrasing;
Everyone stopped saying React is fun after Redux.
From my understanding managing state is a fundamentally hard problem, and Redux just make it very explicit and avoid the confusion of a state living in multiple places.
Did not try Vue but is the state management simpler?
react-redux, which is neither redux nor the only way to integrate redux with react, is a bit more complicated but still not very complicated.
Vue.js might be better than React in some ways, but is it enough of a paradigm shift to throw away a bunch of hard earned knowledge?
React was in the same spot a few years ago. It went from a dark horse to the default over the past two years.
just ask any ex-angular devs.
Just like Github stars arent representative because only (active) Github users would add a star and when a project has critical mass, the amount of actual users will no longer correlate to the amount of stars.
Anyway, I don't think there is a good way to measure usage or popularity of these frameworks. Maybe Google Trends or stackoverflow tags? I don't know really.
Stackoverflow tags comparison here: http://imgur.com/a/O3mSB
The tool used is here: http://data.stackexchange.com/stackoverflow/query/201360/que...
I felt happy looking at this. Angular has everything (the complete package of router, speed, and all the components you need), and was surprised why react was more popular
See https://npm-stat.com/charts.html?package=react&package=vue&p...
A funny pattern that emerges in the above chart is that downloads drop sharply on weekends. I have seen packages that exhibit the opposite pattern (downloads spike on weekends). And this pattern is correlated with popularity, the most popular packages are downloaded largely by 9-5 industry coders, and mostly via continuous integration bots.
Google trends is more useful.
https://insights.stackoverflow.com/trends?tags=angular%2Crea...
For me Vue.js is like a light-weight Angular 1, in a good way. It's very intuitive and you can start working immediately. It does however easily end up in confusion about where the state lives with the two-way binding. I've run into a lot of implicit state changes wrecking havoc. The declarative nature of React definitely wins here, especially working with stateless functional components. If you're serious about Vue you should adhere to unidirectional bindings, components and use Vuex.
The best thing about Vue.js for me is the single file components. It's such a nice feeling to know that everything affecting a certain component is right before your eyes. That's also the reason I started adapting CSS-in-JS in my React components.
The biggest problem for me with Vue.js is the template DSL. You often think "how do I do this complicated tree render in Vue's template syntax? In JSX I would just use JavaScript". For me, that was the best upgrade going from Angular to React and it feels like a step backwards when using Vue.js.
> I've built semi-large applications in both Vue.js and React. I like both but prefer React.
> If you're serious about Vue you should adhere to unidirectional bindings, components and use Vuex.
> The best thing about Vue.js for me is the single file components. It's such a nice feeling to know that everything affecting a certain component is right before your eyes.
>The biggest problem for me with Vue.js is the template DSL. You end up with the "how do I do this complicated tree render in Vue's template syntax?
Also, here's the obligatory "Vue supports JSX" link: https://medium.com/js-dojo/using-jsx-with-vue-js-846f4fbbf07...
I personally feel that JSX feels a bit "unnatural" compared to Vue's DSL, but that's a matter of opinion. It's always good to have the option :)
For newcomers like me, I've found these videos very useful: https://laracasts.com/series/learn-vue-2-step-by-step
Extra tips:
* use axios to transfer data, no need for jQuery
* when you find yourself reaching for jQuery to change DOM, eg add/remove a class, think again. v-if depending on component state data variables worked well for me.
* after trying several authentication libraries, found it simpler to build my own layer, storing user state in Vuex
Anybody has more tips to share? Something you wish you knew earlier?
With that said, there are so many VERY smart people embracing React, so I am always questioning my "hate". Maybe one day I will change my mind.
I haven't use Vue but watched/read about it and seems very cool and simple to use.
For now, my favorite framework by far is Ember JS and it really blows my mind why it is not the most popular framework out there. The amount of stuff you get out of the box and the incredible productivity and happiness it brings to the developer experience is IMPRESSIVE. It will take you 2 weeks of work to make a new React app have the same feature set as an Ember app*
* I could be wrong.
I’m of the opinion that Angular is much better than Ember (note: I have 4.5 years of experience in the Angular ecosystem, including in open source), and I think I am overall perhaps more productive with React than Angular, although I feel like there are less issues with state management in Angular, which has been a pita in React. All the libraries/frameworks have various tradeoffs ultimately, so I don’t believe there is a cure all for everyone’s preferences.
A note about JSX - I am not a big fan of it, but I see it more as having tradeoffs like more traditional templating languages, but different ones. I have been a bit resigned that this is the direction the ecosystem has turned towards, so I have personally decided to hold that dislike more loosely and focus on more important architecture issues. It does little good to let dislike over style paper over higher level issues if you can help it IMO. I don’t think we’ll ever see a perfect template language.
There's something very unlikeable (to me) about basic things like a router not being in the library (or should I say framework) I'm choosing.
I like the way how you articulate your thoughts about keeping dislikes aside and focusing on architectural issues more.
And the original team could have been more junior, or if similarly-experienced than your 2-person team, adding more people to the team without good leadership can also affect productivity---or as they say in Scrum, "velocity".
The problem with that is that the document, application state, and styling is all highly coupled when dealing with web apps. Web pages which are content based are fine with these being separate, changes to one don't necessarily affect another.
For web pages, the separation of languages is a separation of concerns. However, for web apps, the separation of languages becomes a barrier, since everything about a certain behavior in your program could be in three different languages or more.
React changes this notion with the idea of a component. A component is ideally pure, meaning that it affects itself and it's children, and nothing else in the application. Components are composable, so you can combine multiple components, allowing for very DRY view code.
Idiomatically, React components have elements, styles, and the relevant code in a single file. This keeps things encapsulated and easily maintainable.
Grouping logically related components together makes perfect sense (and this is coming from a backend Rails dev who thinks the rails directory structure is totally wrong as well).
You're probably right about this. But it's not always the whole story - maintain and grow your app for a year, and you may find your experience shifts dramatically.
Disclaimer: I haven't used Ember for anything but the tutorial, and I hear it's pretty good these days.
Blog post accompanying said example: https://medium.com/front-end-hacking/how-it-feels-to-learn-j...
I'd be interested to see the equivalent vue.
Would love to see a side-by-side comparison of complex nested data structures in Vue and React.
I think I'd prefer to have a component directory with HTML, JS/TS and CSS/SCSS files in.
If you're using vscode add plugin "Template literal editor" and you get full intellisense on the CSS too!
Can someone actually justify it without handwaving statements like "you'll notice at scale", or red herrings like "Angular is slow"?
If you start adding dynamic forms, multiple developers, unit tests, and advanced interactive application logic, then you are left with a spaghetti code mess (with 2-way binding). The problems really creep up when you start adding observables or watchers, which watch a particular variable for changes. If you two way bind a UI element with a controller variable, and then have watchers or observables on that variable...it is now no longer clear what side effects you're triggering as your interacting with that UI element. Wonky things can and will happen to you as your app's complexity grows.
I've heard this argument before, and I really don't get it.
Let's say I have an input bound to a model variable. What does that mean? Well, the model is the single source of truth of state. And the user can change it. Sometimes we have derived state, like computeds in Knockout. These are read-only and are not ultimately sources of truth (though they will never contradict non-derived values).
In this model, I cannot see what is wrong. Why do you need to reason about the side effects your input triggered? Your input should be bound to something that is a fundamental, atomic, irreducible element of the app state. When it changes, the app changes. You never need to reason about this happening because there should never be a moment where a model changes and the app does not.
Excuse me for my naïveté, but it looks to me like two way binding can only cause problems if you are binding inputs to derived values, or if your model is not truly irreducible. In which case, you are knackered before you start: how is your app ever supposed to guarantee consistency of state?
If you are writing Angular or Knockout code properly, in my opinion, the data flow should be unidirectional just by dint of using an irreducible model and never manually overwriting a derived value.
Just because the template has a two way binding to a model does not mean the data flow is pandirectional. Likewise, one way binding does not guarantee unidrectionality: I am fairly sure you could write a React-Flux app where components emit arbitrary actions in response to state changes. Perhaps this is banned in Redux, though.
But having worked on complex dynamic form generators and enterprise apps at scale, I've seen the mess that KO observables and Angular $scope watchers create in practice.
Neither KO nor AngularJS actively encourage great patterns for data flow in their architecture design. It becomes all too easy, in some deeply nested directive or KO observable, to reference external/parent context or scope. React was specifically opinionated about this because Facebook hit real problems in production with two way binding.
Another benefit of one-way flow is that it becomes trivial to refactor your UI into modular components. Because the data flows in a top down manner passed in as props, it's easy to break up a complex component into several sub components.
React encourages you to fall into the "pit of success" by its design and there's very few traps.
The side-effects problem was certainly true with Angular.js - it is not true with Angular.
At least that's what I've seen it come down to.
In reality these programmers don't want to have the feeling they might have made the wrong choice when they used X instead of Y. The idea that they might have taken the poorer choice hurts so much that they need to defend their decision so heavily while in reality taking ReactJS or Vue.js is like ordering pizza or pasta. You usually don't want to have both at the same time. So you need to explain why pizza is better than pasta tonight. Only that you usually have to stick longer around with Vue.js or ReactJS once chosen. Enjoy your choice and solve real problems, but stop fighting about it, programmers. Pasta and pizza will always both win.
The reality is it is all shite! Just get your job done.
I completely misunderstood your comment. I might need to go get food soon.
Whether you choose pizza or pasta depends on your personal taste. And maybe on your skillset, if you need to prepare the food. Both lead to mostly the same outcome – your satisfaction.
Whether you choose React JS or Vue.JS also depend on your personal taste and skills. Both lead to a finished product.
Here is an example on which I'd love to be proven wrong:
https://jsfiddle.net/j2sxgat2/2/
Its a generic spinner component that waits on a promise then passes off the fetched data to any other custom jsx. It can also take onFulfill and onReject handlers to run code when the promise resolves.
The concrete example shown in the fiddle renders a select list with the options received after waiting for a response from the "server". An onFulfill handler pre-selects the first option once data arrives. The observable selected item is also used from outside the spinner component.
With React+mobx and JSX its all simple functions/closures (some of them returning jsx), lexical scope and components. With Vue I'm not sure where to start - I assume I would need to register a custom component for the inner content and use slots?
or introduce new and weird concepts to replace things that
are easy, familiar and often better designed in the host
language.
Oddly, that's exactly how I feel about the "{condition_expression && template_evaluation}" idiom in JSX. { do {
if (condition_expression) {
template_evaluation
}
}} { do { if (condition_expression) template_evaluation }}
But I gues thats not really better.I'm hoping jsx will eventually default to `do` expressions though, and then it becomes
{ if (conditional_expression) template_evaluation }I have sometimes been caught out by doing `{somearray.length && thing}` though, which leaves `0` hanging out there in the false case...
https://codepen.io/Kradek/pen/JyLPaL?editors=1010
I really haven't run into anything I could do in React that I couldn't do in Vue. What I mainly miss in Vue is react-native.
1. Render methods make vue basically the same as React plus MobX, right? (and afaik you can use JSX too)
2. The spinner component was registered in the global scope. Will normal build tools know about the file and properly include it, or an import will need to be placed somewhere for that to work? What happens if another module registers a "spinner" component? ES6 and CommonJS modules have already solved this elegantly, and I believe its a must for larger scale applications that may consist of multiple complex modules
3. I see many wheels being reinvented, and as a non-vue user I have no idea what they mean. For example, does `<template scope="data">` name the first argument passed to the function? Is `default` the name of the first unnamed template? And this page is utterly baffling: https://vuejs.org/v2/guide/components.html#Scoped-Slots as I cannot figure out which thing is the template that is being passed arguments and which is doing the passing (and how).
edit: re (3) I finally got it, a `template`'s `scope` gives the props passed to a `slot` a name.
It seems to me that templates look like less learning initially, but they end up being more...
2. Again, this was basically just a choice for the example. The spinner could be defined in a module and imported/registered locally. Codepen/JSFiddle just isn't the greatest place for that kind of example.
3. Scoped slots are a way for a component to expose internal data to elements contained in a slot (content thats contained within the component but defined by it's parent). I agree, its initially one of the more confusing concepts in Vue.
<div>
<img v-if="this.status == 'pending'"
src="https://media.giphy.com/media/10kTz4r3ishQwU/giphy.gif" />
<slot v-if="this.status == 'success'" :list="this.data"></slot>
<div v-if="this.status == 'error'">{{this.error}}</div>
</div>
Then in the template the option line becomes <option v-for="option in data.list" :value="option">{{option}}</option>
Not too bad. Guess I'll have to come up with a new example of what Vue templates can't do now!When I first saw VueJS I had a hard time understanding how it would be any better than React, that is until I saw single file components.
https://vuejs.org/images/vue-component.png
I fell in love with the eloquence of being able to separate my HTML, JS, Styles for a single component.. it seemed /right/ to me..
In any case, I've been using VueJS ever since for my new projects moving forward and I'm very happy with it. It has everything I would ever need from React but in what I feel is a more polished and thought-out way.
Just my two cents :)
It's worth noting that Vue also supports render functions with JSX (https://vuejs.org/v2/guide/render-function.html).
I do like jsx for simple things but always felt it bogged down the design piece having to convert even if its just the class to className
JSX is no more than sugar for vdom function calls. You can use React without JSX, and you can use Vue with JSX.
> When I first saw VueJS I had a hard time understanding how it would be any better than React, that is until I saw single file components.
> I fell in love with the eloquence of being able to separate my HTML, JS, Styles for a single component.. it seemed /right/ to me..
You… can do that just fine in React? The logic and "template" are in the same file in the first place, and there are solutions like styled-components, csjs or react-styl if you also want the JS.
Of course you can, these are open sourced projects and you can modify and add packages to do just about anything you want it to do.
However, when presented with an option that is designed from the ground up to work exactly the way you like it, why not use it?
I can install a dozen different packages along with React so that I can get it set up exactly how I want, or I can just use VueJS whose creator's philosophy are more inline with my own and is designed exactly how I like my front-end.
If you want a full blown huge application to last years, then go Angular... Although who knows if Angular will be there in 5 or so years.
There is no perfect library/framework but I love Vue because Vue does exactly what it says on the tin.
After what they did with Angular 1 -> 2 not a chance.
At least with Vue you can swap it out a lot more easily if it does go away in 3 years.
I tend not to pay serious attention to technologies until they are popular and have been used for a while (I always adopt on the back side of the hype/productivity curve, since I'm not completely a front end developer).
However now https://www.webcomponents.org/elements has over 1k elements and Polymer slack channel is over 8k users, the community is active and there are lots of enterprise users adopting it (Netflix, IBM, GE, EA - not only Google).
IMO while that is not bad at all, react is obviously more popular, but when we talk about hype driven development - VueJS is one man project as you can see on GH, 99% of code is by single contributor - but based on hype you would feel safe adopting it.
I think you should just do a tutorial in them and pick what fits your brain.
I understand DOM and elements so Polymer it was natural pick for me, also interoperability with other frameworks/libraries was important factor, they want to be the jquery of webcomponents basicly. I made my bet on a solution that is baked in inside the browser, since webcomponents are W3C standard, and polymer is really small (20kb), it won't suddenly stop working for me the same as jquery work for billions of people.
On the other hand, a lighter Web Components library I've been looking at has been Xtag.
I also think v2's switch to ES2015 classes instead of v1's prototypal inheritance is much better and cleaner, but that's more of a product of Web Components v0 vs. v1. :)
Why are then Vue components written in .vue files and compiled to Javascript then? ;)
.vue files are there for simple single file components[2].
[1]: https://jsfiddle.net/yyx990803/y91wy85p/?utm_source=website&...
I've done many Angular apps. I've done a bit of React (with Reflux & Browserify).
I tried moving to React/Redux/Webpack but it's not an easy task to grasp the whole thing. Webpack itself was close to make me throw the towel on side projects.
I tried VueJS because of a job interview and quite liked it and got productive really fast thanks to good documentation and my previous experience in angular & React.
Professionally I wouldn't mind any of those but for side projects it will be VueJS from now on.
As a side note I don't get why all the boilerplates always mix backend and frontend code and dependencies. If you're not interested in a node backend and learning it's overwhelming.
The worst thing is that boilerplates you find are always outdated (router, hot-reloading etc) and worst of all mingling server and client deps so if you're not interested in a node backend you have to
And, once you have all that working, staying up to date without bugs due to version mismatches can be a real pain.
https://vuejs.org/v2/guide/comparison.html#Polymer There are some similarities shared between polymer and react/vue (personally only used react and angular 1.x before).
I've built applications with it using polyfills and things worked just fine with legacy applications on IE10 + jquery interacting with web components.
Performance is nice, there is more and more adoption from giant enterprises like Netflix, IBM, GE, Gannett, Electronics Arts, CocaCola, ING, BBVA.
Webcomponents.org has over 1k components to choose from and is growing.
Now with `lit-html` arriving soon we might see alternative to JSX if someone wants that, polymer-redux or polymer-uniflow is available as an option too.
https://hnpwa.com/ - one of fastest Hacker News implementations is based on Polymer - and that is even without SSR.
SvelteJS also seems nice, although it seems one-man project for now :( On Polymer end I hope that on the summit next week they will announce proper NPM support finally and I miss that.
Sure, you don't have to use it, but it's the main selling point of polymer. It seems nice in theory but npm also seemed nice in theory.
But I do agree that too much fragmentation can be a problem.
I use SvelteJS on both the client & server side. SvelteJS also has a rehydrate feature, which allows you to render html on the server & then bind the Component on the client.
Also, the Shadow DOM is one concept that I liked in theory and hated in practice. Made it very difficult to do very simple styling tasks that were accomplished easily with plain css and proper naming (e.g. having parent components provide default styles for child components).
The polymer bundler in 2.0 is a buggy mess (it's still in beta) and I couldn't find any decent way to use Webpack with Polymer.
Many other complaints about Polymer that I won't go into. It's way too green in my opinion and I'd recommend avoiding it for at least the near future.
IMO having everything inside Shadow DOM is an anti-pattern.
I use my own pipeline based on gulp so I don't know much about polymer bundler, webpack support was recently added though, I haven't used it yet.
- React Native (I know there's Weex but it's not production ready, nor as feature rich)
- Streaming server side rendering
- React Relay (GraphQL integration)
- JSX by default. VueJS pushes an Angular-esque template language where I have to learn new syntax, binding concepts, directives and conditional statements.
- Corporate backing
I've used React in very large projects, where these features have been fairly critical. React's licensing is odd but not odd enough for me to ditch it. I'd really hate to see the community churn once again on frontend libraries, but that's JavaScript for you I guess.
of all the frameworks, vuejs has the simplest syntax to learn. its no where as complex as angular and way more elegant. also beats jsx in terms of making your code more cleaner and prettier. im never going back to jsx.
Not sure about the original poster, but I prefer react/jsx not because it's simpler, but it's more powerful - it's a simple extension to a full programming language. You can do whatever you want with it.
it's just less coding and boilerplate if anything.
vue also optimizes your reactive codes and is faster in many cases. react can get pretty slow and heavy if you don't know what you are doing and trying to debug those situations can get pretty hairy. otoh, i've not seen any similar issues with vue. what vue does with the bindings is really neat.
<button v-bind:disabled="isButtonDisabled">Button</button>
<div v-bind:id="'list-' + id"></div>
<form v-on:submit.prevent="onSubmit"></form>
<a @click="doSomething"></a>
There are some redeeming qualities compared to say, Polymer. But it's neither clean nor pretty <button :disabled="isButtonDisabled">Button</button>
<div :id="'list-' + id"></div>
<form @submit.prevent="onSubmit"></form>
<a @click="doSomething"></a> button(:disabled='isButtonDisabled') Button
div(:id='`list-${id}`")
form(@submit.prevent='onSubmit')
a(@click='doSomething')JSX is incredibly simple. Why would you do that to yourself and other devs?
And it's far from being simpler
@click="say_something('hello')"
new Vue({ methods: { say_something (str) { ... } } })
2) : is just a shorthand for v-bind (ie; v-bind:disabled="is_disabled()" is aliased by :disabled="is_disabled()"). and this basically allows you to run pure javascript code inside of it.
3) the only other syntax to know is, v-for and v-if, but thats pretty self explanatory i believe.
<h3 v-if="user.name">{{name}}</h3>
<h3 v-if="!user.name">What is your name?</h3>
<h3 v-if="user.role == 'admin" && user.name == 'james'>hello super user {{name}}</h3>
i like this approach more than JSX where you have several if else clauses mixed into your HTML. it's kind of like pattern matching if you like that sort of thing.
or you can simply do <h3>{{some_message()}}</h3> and just handle the logic inside the some_message() method.
2) shorter to write and simpler to read
2) Shorter is not always easier. For example, using quotes to delimit logical expressions makes it easy to make errors. See the misplaced quote here?
<h3 v-if="user.role == 'admin" && user.name == 'james'>hello super user {{name}}</h3>That's the thing. You do not really separate js and HTML.
There's a weird extension to HTML. There-are JS-like expressions, JS expressions and bindings to outside JS code
It's also neither shoryer to write nor easier to read.
This feature appeared in React v16 (which is still in beta). Vue had it long before.
https://ssr.vuejs.org/en/streaming.html
Thanks for pointing out that it has it.
https://www.nativescript.org/blog/a-new-vue-for-nativescript
<a href="...">Link 1</a> |
<a href="...">Link 2</a> |
<a href="...">Link 3</a>
It's not Link 1 | Link 2 | Link 3
as you'd expect - instead, the whitespace after the pipe character is eaten by JSX. This is because HTML is whitespace sensitive, but JS is not, and so to allow indentation, JSX trims whitespace.Here's another -
<dl>
{ Object.entries(definitions).map(([term, definition]) => (
<dt>{ term }</dt>
<dd>{ definition }</dd>
)}
</dl>
This does not work - instead, you need to return an array, but the result is ugly - the commas are part of JS, not HTML, and don't appear in the output, but reading this quickly it's hard to see that (the difference is the braces surrounding the block). <dl>
{ Object.entries(definitions).map(([term, definition]) => ([
<dt>{ term }</dt>,
<dd>{ definition }</dd>,
])}
</dl>
Vue's 'weird DSL' is HTML (the same is not quite true for Angular's). What you see is exactly what you get. Having a DSL also means you can define your own syntax. Things that are verbose (due to historical reasons in JS), such as iterating over an object, can be made simple - <dl>
<template v-for="(definition, term) in definitions">
<dt>{{ term }}</dt>
<dd>{{ definition }}</dd>
</template>
</dl>You still have to understand html inside weird jsx code...
{' '}
Not the prettiest, but doesn't come up often in my experience.On the 2nd point, you are partially correct. In general it's a code smell - strongly consider making it a component (in part for optimization). But definition lists are specifically strange: Unlike other repeating elements in HTML they don't have a container element like tr, li, fieldset, etc.
<button v-bind:disabled="isButtonDisabled">Button</button>
<div v-bind:id="'list-' + id"></div>
<form v-on:submit.prevent="onSubmit"></form>
<a @click="doSomething"></a>
Something tells me JSX is the better DSL. <button :disabled="isButtonDisabled">Button</button>
<div :id="'list-' + id"></div>
<form @submit.prevent="onSubmit"></form>
<a @click="doSomething"></a>
It gets really, really clear that anything not in {{ }}, or attribute not prefixed by @ or : is HTML.The only way I see that as being more "intuitive" is if you're familiar with other templating languages.
JSX is far clearer:
<button disabled={isButtonDisabled}>Button</button>
<form onSubmit={handleSubmit}></form>
<a onClick={doSomething}></a>
All you really need to know is everything between braces is plain JavaScript, and property names are camelCased.I have a Typescript + Angular 1 project. The app logic feels robust as Typescript makes sure I'm using the right identifiers, variables aren't null/undefined etc. The Angular templates are a constant source of annoyance: they aren't type checked and aren't part of automatic variable renaming refactorings.
Can someone confirm that you cannot type check Vue.js templates (without using Vue.js JSX support of course)?
For the Angular 1 project, I'm thinking as a stepping stone we could introduce JSX templates before migrating to Vue or React later.
Of course this only really matters if you use Typescript/Flow.
Surprised I haven't seen this mentioned more in the thread.
Inability to have the same level of control over soft keyboard behavior is one of the top problems with Cordova, IMO.
Source: wrote & maintained a Cordova+React app on iOS/Android for 3 yrs.
I mostly worked on games, where the UI is custom and there are very few similarities to the UI of the OS, so it worked pretty good.
Vue.js and Angular are complete non-starters for me since they don't have native counterparts.
How is JSX more complicated than any template language?
How are Vue components any simpler than React components?
You can write JSX with just script embed.
I looked at React, but without a cohesive framework, that ecosystem is just a bit too much of a mess. A gazillion starter app templates that can't quite agree and always seem a little out of date with the fast moving components. JSX is just ugly. At least to me. I regularly use Django templates, so the clean leap to Handlebars-style templates feels very natural to me. Redux is straight up unapproachable to someone new to the concepts, but at the same time it feels like it simply reinvents events and event handlers.
Vue was a revelation. It is simple, cohesive and I feel productive.
Polymer v2 in a web browser that supports Web Components v1 should be pretty fast, though. But that was only released last May.
You should also give ClojureScript with the simple React-wrapper Reagent a spin. All the functional stuff is built into the language, like Elm, albeit without the types, which both has its pros and cons.
The main things that I like so far;
* Single file components - I actually really like this, I find it much easier on my brain to have everything related to a component in the same file.
* The router and data modules - having the router and Vuex as "official" parts of the ecosystem (as opposed to in React where they are "adopted") means that everything just clicks.
* Styling - when I first started out with React, it was a pain to find a nice way to do CSS - do you use modules? Just have files that you import? Inline? Having it automatically scope the styling to the component if wanted, or using modules if thats your thing - is so much nicer than having to think about it. I just add <style lang="scss" scoped> and I don't have to worry.
The only downside I have at the moment, is having to learn the "v-" bindings (which is what put me off Angular when it first came out) but I think that it is something I can live with. Although you can use JSX and have a render method so I might try that and see how that flows for me.
For example, for one of my libraries I wanted a really simple way to allow people to include custom templates. I started with string-based templates, but quickly realized that this was inflexible for any kind of event binding or later dom mutations. Achieving that was super easy with jsx -- I just implemented a custom jsx function which directly outputs DOM elements.
Step 1: implement a jsxDom function [^1] which takes (name, props, children) (e.g. https://github.com/krakenjs/xcomponent/blob/master/.babelrc#...)
Step 2: point babel to my jsxDom function (e.g. https://github.com/krakenjs/xcomponent/blob/master/src/lib/d...)
This even allowed some cool hacks like including iframes directly in the jsx, to sandbox sections of the page (since the library is geared towards creating components to be embedded on 3rd party sites):
containerTemplate({ jsxDom }) {
return (
<iframe>
<style>
p {
margin-top: 40px;
}
</style>
<p>I can be sure the styles in this iframe won't affect the parent page</p>
</iframe>
)
}It looks pretty clean and grokable in the examples and deals with async out of the gate -
Here's a medium size store for a project I worked on: https://github.com/tmm/notational/tree/master/src/store
I won't be using this as it definitely sets off my library-depth spidey sense.
The multiple libraries it abstracts would all change versions over time and lead my applications to be even more brittle.
Vuex being mainline with Vuejs is a major plus as I look at its long term stability, though whether it insists on vuejs I need to look into.
For the library-depth spidey sense, there's really no getting around that. In a way, as React itself is just the view library, you're forced to add new pieces to your app until it all clicks together. Kea is just one more of these pieces... And I wrote it so the other ones would click together. The alternative to abstracting libs like that is to write and bundle everything yourself, but that is a hard and, in this case, unnecessary path to take.
Two of the libraries it abstracts (redux and reselect) are as stable as a rock. There have been no breaking changes for many major releases. The third one, redux-saga, is a bit more brittle, but as it gets passed direct control over its domain, I don't see how kea would break anything there, at least not in the near future.
Of course I'll do my best to keep up with new releases of all dependencies. I do have a few apps with Kea that I actively maintain.
There's still the chance that Kea itself will change drastically. I hope not. I'm actually trying to stabilise the API for a 1.0 release.
I dont see much of this problem, including myself as one of these just hired jr devs.
I need a framework where any experienced JavaScript developer can pick up the project and deliver working product in a week. With Ember/Angular/React+Redux, I have to hunt for a developer that specializes in that particular framework. With Vue, the hiring pool is vastly larger.
But if you find value in dropping in a CDN link, you can use React and Babel that way too.
> think like Vue is a new jQuery
The simplicity of the nested, inception style architecture of React makes it super easy to onboard and up-ramp.
It's not about taking a massively existing complex application written using one of VueJS or React and onboarding someone completely green into it. Adoption is about "how easily can I incrementally adopt this technology into my legacy app". And the problem is that React is nearly unusable without switching entirely over to a Webpack / transpiler system and learning JSX, which makes it almost a non-starter for someone who isn't planning a major rewrite of their legacy app front end. By contrast VueJS "just works" after dropping a simple JS bundle into a page and the first templates you write are barely distinguishable from regular HTML. You can start by just enhancing the odd page element here and there, and slowly build up to a fully based VueJS app.
Not just learning, JSX/React.createElement approach is the hell itself, it increases the technical debt every time you use it, but some people prefer to make a blind eye to this. When juniors come to work with React I guess it makes them think that React way is the only way, but it's more like the 10 years old PHP code.
Let's imagine that for some reason in 2-3 years there will be a silver bullet like framework. So most likely hipsters will be going to switch to it and I'd like to see how they will be cherry-picking all the template's parts from the JS/JSX code to the single holistic template (I don't think the sliver bullet like framework will follow the mixing template with code ideas).
Edit : Also wanted to add, while I think a lot of people really don't like JSX, I actually do like it but I think someone could take that aspect and come up with a better state management system outside of redux and friends. I think something along the lines of Angular (not AngularJS) with JSX would be great.
This sounds awful and seems like an anti-pattern. I don't think this anything to do with React (other than perhapps that React gives you the freedom to do things wrong). Your devs don't have a proper understanding how React (or Vue) works. Define state model, define view, modify/interact with state, let React modify view. That way you'll never need dirty hacks like fetching state from Redux by using the DOM ID.
Everyone talks about react, angular and vue.js. How about Polymer?
What are your experiences with it, if any? I'm no expert in either technology, but Polymer seems much more lean, needs no build process as far as I know, and is quite flexible.
Why wouldn't it be an option to replace react/angular/vue? Any thoughts?
Building Polymer components is very similar to building Angualar 1.5 `component()`s or react components (or actually any component system for that matter).
New elements are true DOM nodes which is quite an advantage in my opinion.
You can add redux/uniflow on top of that or some vdom lib like preact too if you need that - I wonder what will come out of `lit-html` that is supposed to be vdom alternative.
One interesting thing one should understand that applications view components that are not meant to reusable should NOT use Shadow DOM (just regular DOM)- this way you can use bootstrap or whatever else to provide "traditional" styling of your application.
BTW I think right now Polymer also requires a build process - because 2.0 is written in ES6 so that means building to support older browsers like IE10/11.
1. I couldn't CSS style a Vue component. I find components very important and they should behave like HTML elements. It should be possible to write a <video> element in Vue if that element didn't exist.
2. I find the state management Vuex somewhat an afterthought. Some people say you will know when you need state management, but I think if the integration of state management is really seamless there is no need to avoid state management even for the most simple apps. So don't listen to these people and start with Vuex straight away, even if it takes a little bit more effort.
I'm sure that there are more points for an even better solution. However for the moment Vue seems to me the simplest, the most elegant and most intuitive framework. So I will use it for my future projects.
If you need to override child component styles from a parent (bad idea in 99.999% of cases), /deep/ would work.
This idea with stylable components is for a different framework, perhaps.
In React, everything is just JavaScript. Not only are HTML structures expressed via JSX, the recent trends also tend to put CSS management inside JavaScript as well.
for me this is the deal breaker, just JS should be enough.I completely agree that React can feel like overkill for simple stuff, but really shines as the apps get more complex - complexity feels a lot more manageable.
For example, I built this in-browser Illustrator-inspired site/app using React and couldn't have imagined doing it without (in terms of making managing state and reasoning about things easy as the app grows more complex): http://f37foundry.com (the type tester on the desktop homepage, apologies for limited browser support!). Curious if you could do that sort of complex app with Vue.
The rest of the site is pretty basic granted. Maybe it's not a great example, but it's the sort of thing that could have easily become unmaintainable in the old days as features were added quickly, but React and the component model (and MobX) made it much more manageable even as I hacked things in last minute ;)
Once you do click it, I'd say the complexity of the site becomes more clear.
Or maybe my reference point for "complexity" is just low.
Regardless, very cool site. Nice work!
And worst of all, it actually obviously works in Chromium and Firefox, but you just check the UA.
Works:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36
Doesn’t work: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/60.0.3112.90 Chrome/60.0.3112.90 Safari/537.36
I mean, sure, if you want to build a site that relies on ridiculous UA testing, and breaks everywhere, sure.But not even in the "works best in Netscape" era did people actually intentionally break their pages in browsers where it actually worked. This is a new low. This is completely ridiculous.
Proof: http://i.imgur.com/YlPE77b.jpg Oh, and as you can see, if I spoof the UA in FF; it actually works fine. This is completely bullshit, and I’m sure I’ll never do business with you. This is completely ridiculous, leaving out major browsers (and, for example, over 40% of the desktop browsing market in Germany) intentionally and unnecessarily.
Given the target audience (graphic designers, the vast majority of whom are on Mac and will use Safari or Chrome, as I validated from stats on other sites I've built), the decision was made to focus work on the type tester on those browsers.
The rest of the site should still be accessible with any browser, but we decided it was better to not show the type tester at all than have a broken experience (which was the situation with Firefox).
Anyway, hopefully that justifies it somewhat - I think it was the right decision all things factored in. There's a lot of CSS trickery/hackery to make the type tester work (native support for advanced typography stuff is poor) so making it x-browser wasn't easy. The messaging to users of other browsers could probably be improved though :)
It doesn’t even work on Chromium, in the same version as Chrome. There is literally no excuse for that, it’s literally the same browser engine.
On top of that, even back in the "best viewed on netscape navigator 4.0" era there was a solution for this: Show a message that it was only tested with browser X, and that your client was too cheap to pay for anything else, but at least allow the user to bypass that.
As said, the excuses convinced me even more to never do business with you.
Moreover, you failed to acknowledge the points they made in response!
The loop of "everyone only uses chrome" → "I only need to support chrome with my website" → "nothing works on firefox, I'll switch ti Chrome" is harmful to the entire internet industry, and the startuo economy.
It is harmful to all of us, and hurts all of our future.
I see their situation, and their limits, but this is a very egocentric opinion that completely ignores the effects on the rest of society, which is an issue that's just all too common (see also monopolistic effects, or environmental effects, etc).
slowclap
If using a JS framework means you don't have time to test your website in more than one browser, I'll happily continue writing plain JS (or better yet, no JS).
As mentioned in my other comment, due to the target audience it was decided that it wasn't worth the investment to get it working on other browsers right now, but the rest of the site should still work.
Not React's fault, just a lack of time/budget and a lack of native browser support for advanced typography.
Personally, I develop Firefox-first and then work on compatibility for lesser browsers like Chrome and Safari.
Of course things have been complicated a bit now that Firefox Focus is out and uses Webkit...
There are some claims that Vue uses two-way-binding which is unmaintainable, but v-model isn't true two way binding and is just syntax sugar for builtin tags: https://v1.vuejs.org/guide/forms.html With React, you would have to explicitly write the event handler/setter out, and some may prefer explicitness (but again, there's nothing stopping you from doing the same with Vue).
Vue just has some nice features (computed properties, better style scoping, etc) and different methods for inheritance/templating (but you can use ES6 classes and JSX if you want to), and like somebody else mentioned, is plug and play (yes, you can technically write React render functions without a transpiler, but do you want to?) while Vue (with the template compiler bundled) lets you write templates with HTML attributes using just a script embed.
There are a bunch of other arguments that are more nuanced (ecosystem, bus factor, etc..) but from what I've experienced, Vue is no worse at scaling than React simply because they share the same conceptual model.
that's somewhat bothersome... does it typecheck on compile time? hope vue works on typescript-language-specs compliant plugin...
As for react, there's TSX (typescript-jsx) that works great (typechecks on props, state, etc.), but I haven't tried it with vue.
Type checking for props and state inside the <script> tags is fully supported: https://vuejs.org/v2/guide/typescript.html
If you want type checks for inline <template> code (which isn't suitable for anything non-trivial, you should use computed properties or methods instead), see https://github.com/DanielRosenwasser/typescript-vue-tutorial
If you are using uncompiled components (newbies using script embeds) with no build step at all, there are clearly no compile time checks. IMO this is why Vue is significantly more newbie friendly.
My only suggestion for people starting with Vue is to not be afraid of directives (Vue directives are nice and have nothing to do with Angular directives), group your .vue components into directories and don't jump into Vuex right away (same goes for React beginners, don't force yourself to learn Redux for your 1 page app).
so does Angular
How much simpler than functions as components, that get their props as parameters could it get?
Every example of Vue components I have seen was more complicated...
React - has influence wherever Facebook has influence
Vue - took off in China as FB did not bother to proselytize developers there
Where React wins for me:
- Higher order components - Stateless functional components - React 16, especially the scheduler
Also I really like building the virtual DOM directly (JSX) but that doesn't seem to be very popular reading the other comments.
I also make mobile apps. Angular and React have the best native apps as of a month ago.
I use old devices. React and Vue are the most responsive.
Large companies use React on desktop and mobile.
React it is.
honestly react devs are missing out on how great the vue experience is. it didnt take me too long to see how much better vue is.
These are available for both Vue and React. Is there something on top of that available for Vue?
Html templates are a major turn off for me there, and using JSX is not optimal.
The main arguments in favor of Vue.js revolve around the idea that it is easier for new developers to understand; that people can pick it up and immediately be productive, with React/Redux being much harder to understand. As someone who wants to onboard new developers onto my project, it makes me wonder if I need to look into a switch, if not for my current project then for the next one.
A lot of the commonly touted differences are either a wash, or are only benefits for very small applications with perhaps a single developer. These would be Templates vs. JSX (This is a wash, they're the same thing, but this maybe even favors JSX for large applications), running Vue.js without a build system (you will want a build system regardless for any production application), "Two-way data binding" (Fools gold, will cause horrors if you ever use watches, you will end up hoisting almost all of your data to Vuex anyway in a production application) and "Single-file components" (Really skeptical that this will make a difference in development vs. any other organizational strategy). I can expand on any of these, but they've already been discussed to death.
+ Where I think Vue.js is actually superior to React:
Vue.js is quite opinionated and clear on where to put both data and computed properties. That's basically it, but it's a huge difference.
React itself is very hand-wavy about where to put data and how to interact with it; it basically leaves the problem for someone else to solve. Even Redux, which is designed specifically to store application data, has a weird interface to connect your data to the React application and has no opinion on where to put computed properties. React-router suffers from this same problem as well; you basically end up looking for blog posts on Medium to figure out how to construct an actual SPA out of these components.
This is a gigantic failing of the React ecosystem, and I think this represents almost 100% of the perception (or perhaps even reality) that developers understand Vue.js better than React.
+ Where I think React/Redux is still better
The React ecosystem takes a lot of inspiration from functional programming; it prefers "immutability" and pure functions whenever possible, and I think this becomes increasingly valuable as your application grows; not just for enormous applications, but even for medium-sized applications.
Even if you're exercising maximum discipline with Vue by hoisting your state to Vuex, you've still got many opportunities to create difficult bugs based on the mutable state. Are you sure you're not referencing mutated state in one your actions? Does one of your components hold onto mutable state in order to do a custom transition or animation? If you're using watchers, you're really risking some dangerous bugs here. Now, I know you probably won't do something silly like this, but as your development team grows and you can't code review everything going in anymore; can you vouch for everyone on your team not to make a subtle mistake with a mutable reference?
React/Redux also enables a few very useful patterns that Vue/Vuex doesn't offer at all. For example, the famous optimistic application is nearly a first-class use case for Redux, but would be quite difficult to implement in Vue. This doesn't matter for small applications; it does matter for large applications. Will it matter for your medium application? The same thing about Isomorphic rendering; Redux was built with this squarely in mind. It won't matter for your small app; are you planning for your app to be small forever?
Finally, because it is all Javascript, I think React/Redux has a much better ecosystem of tooling. That includes both linters and transpilers; for example, writing Vue in typescript isn't especially natural, but it works great with React/Redux. When considering my own purposes, effectiveness with Typescript is one of React/Redux's greatest advantages.
In summary, I would still maintain that React/Redux is better for medium to large applications than Vue, due to its commitment to pure JS and the inspiration it takes from functional programming. However, I definitely see the appeal of Vue.js, and I wish that the React ecosystem would take a note on how to provide clear opinions for developers.
I'm worried about forward compability of all this React components I'm building
React is for CS-savvy programmers. Vue is for those who like to think of themselves as programmers.
(I would also say the same goes for picking programming languages, as long as it's one of the top ~15, and you stay somewhat flexible.)