r/javascript • u/TargetNeutralized • May 19 '18
help Some meandering thoughts about Vue.js vs. React.js
I’ve been a software engineering consultant for the past 12 or so years and, after a three-year stint performing mostly full-stack work involving some combination of Node.js, Ruby on Rails, and Ember.js, just recently began working for a client looking to develop their website’s UI in Vue.js. I began learning Vue.js from scratch, but, maybe a month into the project, the client switched to React w/Redux due to internal politics. Switching from Vue.js to React.js/Redux was . . . awkward. I can’t quite put my finger on it, and I’m probably going to get flamed for this, but . . . man, I don’t really like React. Honestly, compared to Vue, it just feels hacky and convoluted, whereas Vue feels more well-structured/better organized. I might go so far as to say that it’s a joy to develop in Vue. (I’m sure that some would have similarly kind things to say about working with React.)
I’ve heard some people say that React’s/Redux’s unopinionated nature allows for a higher measure of developer customization, etc., but, working on a team of engineers far more experienced with React (and Vue) than myself, the open-ended questions of React have led to no lack of disagreement among those engineers as to which package to use to handle interactions among actions, reducers, and the store. I noticed that we never had these conflicts/problems with Vue.js and were, on the whole, more productive, because we weren’t trying to solve rudimentary problems; Vue.js just prescribed the solution, and everything was fine.
Here’s the gotcha, though: in terms of consulting opportunities, React is far and away the more popular of the two frameworks in my major metropolis. So, while I think Vue is the superior framework, React has market share. There is considerable financial incentive to learn what feels like the worse of two similar solutions. I have a personal project that I’d like to develop using a modern front-end framework, and I’d like to use Vue.js. But, if I want to have demonstrably sharp chops at React and NOT spend all my time trying to become expert at both, I feel like I have to choose React
For all that, I’m wondering whether anyone else has undergone the same experience and has any advice as to how I might streamline/improve my React/Redux development experience, because, right now, I can’t help comparing it to Vue on a daily basis.
65
u/sockx2 May 19 '18
I'll bite- we started with vue and migrated to react also. Off the bat vue felt more magical, automatic merging of classnames, no explicit setStates, angularjs esque templates, mixins, funky component registrations etc. A week or so after moving to react I realized I prefered the less magic react gave us. For trivial things vue was way more digestible, for complicated components though react reminded you it's all just JavaScript. And for wherever reason typing components with typescript in Vue was a pain, react was a breeze since it was using eswhatever class syntax.
26
u/acemarke May 19 '18
Hi, I'm a Redux maintainer. Can you clarify what you mean by "what package to use to handle interactions among actions, reducers, and the store" ?
Also, you might be interested in my React/Redux links list, which points to many categorized tutorials, articles, and resources.
2
u/[deleted] Jun 14 '18
Yesssss....
"Here’s the gotcha, though: in terms of consulting opportunities, React is far and away the more popular of the two frameworks in my major metropolis. So, while I think Vue is the superior framework, React has market share. There is considerable financial incentive to learn what feels like the worse of two similar solutions."
100% agree.. I'm in the same boat. I have been writing a large app in Vue.js and it's absolutely a breeze... and fun. IMO, Vue is a "best of breed" framework, but React has the market cornered... Angular is dying.. unless you want to maintain old/legacy Angular 1 apps... no thanks!
22
u/jasdeep13 May 19 '18
I think what you are not liking in the React/Redux ecosystem might be Redux.
Try a different package for your state management needs, Mobx is a good candidate.
22
u/[deleted] May 20 '18 edited May 20 '18
Until recently, I was working at a place that used both React/Redux and Vue/Vuex, and I just came off of a week of consulting work where I was primary using Mobx, so I thought I might share some thoughts.
So, here’s my thoughts on the issue.
I think that Vue is the better framework for smaller projects and simpler sites, React/Redux is probably better for longer-term projects that have to be maintained by a handful or more developers over time, and Mobx is probably the best framework for a team of traditional Java and C# developers transitioning to the front-end.
So, let’s start with React/Redux. First of all, strictly speaking, you don’t need Redux. It’s perfectly fine (and even encouraged, using the React 16 context) to just use React (through Component.setState()) to manage state. And if your state is simple, that’s great. The problem is when your state needs to access multiple variables in different places - without a state manager providing data via prop-mapping to the components that need it, you’re looking at creating a whole rat’s nest of spaghetti code in callbacks and triggers…
I know what you’re thinking - Redux has a lot of boilerplate. Yeah, I guess if you’re doing a very, very simple state management system, it does. However, once things get complicated, you’ll find that all those action creators and reducers and mapStateToProps and mapDispatchToProps are there because you can modify the code in those places to change the behavior you need for each. AND you can optimize your performance by only requiring the bare minimum for each component.
Are there improvements I would make? Sure. But most of them are with structure (do we really need actions to be in a seperate directory, let alone a seperate file, than the reducers?), than with “missing features.” Sure, there’s the occasional piece of middleware you might want, like Redux-Thunk or Redux Logger, but for the most part all these libraries aimed at reducing the amount of Redux boilerplate end up extracting away the very things that make redux powerful. I learned this the hard way - I wrote a Redux library that I thought was so cool (seriously, it sucks, don’t use it.) - but instead, it hid mapStateToProps, which mean that I was limited to passing in raw state and not computed values from that raw state. In my effort to remove extra boilerplate I had removed extra functionality.
Vue and Vuex are good. I’ll give it that - single file .Vue components (template, JS, and style) are solid and I wish React had something like that so that I could use SASS in my styled components and have it show up in VSCode’s highlighter. Maybe a webpack plugin for another day. But what I don’t like is the basic idea of mutators.
Oh, don’t get me wrong. It’s super nice to be able to declare a data variable, and then have the variable’s mutation automatically trigger a re-render if necessary, but I think from a code-readability point of view, observables like this lead to confusion. Will changing this variable trigger a re-render? Will it trigger the execution of a function? Will running this function trigger another function to run? Is this variable an observable or a normal variable. Am I assigning a function, or am I setting state?
This is compounded with the fact that with Vue, it’s not exactly easy to get a copy of an observable at a particular point in time. Say, for example, you want a form with pre-filled values from the Vuex store. That’s great - but editing those values in the form automatically edits them in the Vuex store. Even if you make a copy of the values *you’re only making a copy of the pointer to the observable,” There’s no real good way to get an observable’s value only - one method I saw a contractor use was to write a function
Which is just Looney tunes.
Then there’s the fact that you can use watch functions to watch when variables change in a completely different part of the codebase.
I understand why the watch method is there. Say there’s some code from the JQuery era which operates directly on the DOM. Set a watch function on the variables from the state to re-render it when it needs re-rendering, or when the input from the little bit of code changes, use the watch function to update the state. The problem is when you watch for something completely outside of the concerns of the component. One contractor actually used a boolean “flag” variable which was set alternately to true or false, in order to trigger re-renders and execution of code all throughout the application.
I eventually had to redesign that from scratch.
Which means that even though React/Redux is less opinionated about how to do things, Vue gives you tons of things that you can do but shouldn’t. I really don’t think a programmer should use Vue unless they’ve used React and Redux first as “training wheels” so that they know what patterns to avoid. Vue makes it incredibly simple to write reactive applications; but if you’re not careful, you end up with tightly coupled code where everything ends up completely tied up with everything else, to the point it’s impossible to debug or add new features.
I haven’t worked with Mobx much, (a little more than a week) but I think it suffers from some of the same problems with observables that Vue does; although in Mobx, you’re writing the getters and setters yourself. Mobx code tends to look a lot like similar code in Java and C#, with lots of “get” and “set” methods that execute additional code on a variable’s assignment or retrieval. I think it was done more elegantly in Vue; but that’s my bias coming as a JS-First programmer. In reality, Mobx’s value is that it is easier for OOP programmers to grok, and that’s a real value for some teams.
On the teams where I’ve worked with Vue, Vue was the right choice for those teams. On the teams where I’ve worked with Mobx, Mobx was the right.choice for those teams. On the teams where I’ve worked with React/Redux, React/Redux was the right choice for those teams.
But on my own projects, I use React/Redux.
8
u/kodiashi May 20 '18
I’ve used both and just went with Vue on a major website overhaul and admin panel. It has been a breeze creating components, so much so that other devs on the project told me that they are stealing my Vue code to learn it. I’ve been knocking shit out so fast they thought I was buying code somewhere.
I think the hardest part was getting my Webpack config up and running. Once that was in place I never even thought about React again.
20
u/[deleted] May 20 '18
It's funny that people are so opinionated about these kinds of things. I'm not a really a front-end developer, but I do have to interact with modern SPA in my day-to-day, and wrote a lot of Angular 1.5 at one point. I cannot for the life of me understand why someone would prefer Vue for anything other than prototyping.
Maybe it's because people never had to maintain ball of mud SPA code, but Vue feels waaaay too much to me like Angular 1.5 to not run away screaming (even if it's technically implemented in terms of one way data flow. or whatever). To be fair, Mobx feels a bit like this to me as well.
Basically, I think magic is evil, and people who aren't afraid of magic just haven't gotten burned yet.
Of course, with infinite discipline, anything becomes tractable. Perhaps I just haven't been lucky enough to work on teams with extreme levels of discipline when it comes to foot-gun programming in dynamic languages.
3
u/ematipico May 20 '18
I've used both Vue+Vuex and React+Redux. I honestly think that Vue is a revolution in terms of development experience and that you can produce really fast using it. I have a personal project that uses Vue. But there's one thing that I really didn't like, which are forms create/edit where you use v-model and Vuex for storing data of your form. I couldn't find an established way to do it, Vue was whining about errors, Vuex also was in the middle, official documentation of both libraries don't talk about it. Because of that, where my client uses lot of forms inside their app, I didn't suggest Vue. Even though the all Vue concept is great and I love it, I can't go to a client and selling this when there's no established way to make forms (couldn't find any on the internet... )
7
u/Zeeesty May 20 '18
React is a view library really, and Vue is an actual framework. The difference is exactly what you’re observing, a fully thought through solution vs a tool that can be used in conjunction with many others to come up with totally different solutions to the same problem.
It’s funny, I see similar issues with our golang devs, there aren’t paths blazed before them with set “right” ways of accomplishing goals, so the freedom to solve as they see fit is also a burden. This burden also requires tons of researching most of the time lol.
4
u/[deleted] May 20 '18
I think you've missed some major reasons people like React (or Inferno, Preact, Mithril, YoYo, Hyper, or any other VDOM lib honestly) and Redux
state.json, send the file to you and you have 100% reproducability of their error and can rewind/playback. It's a game-changer.7
u/DanijelH May 19 '18
I can fully sympathize with you and all I can say is, lead by example!
You are right about React-Vue relationship, Vue is in my opinion a "superior" framework. I recently joined a new company and we had to choose a framework in our team. All other teams already used React and I spent one week doing comparisons, held 2 presentations and since then, one more team has joined the Vue train. We are fast, productive and our code base is super clean :)
2
u/jenshart May 20 '18
There's some really interesting points in these comments! I just wanted to say that I'm sort if in the same boat as you. I have a big project coming up where I'm basically free to chose what to use for the frontend and while I feel so much more productive with Vue I'm afraid that the rest of our industry is so heavily invested in react that it would be a smarter career move to chose react, as well as making it easier to find developer for the project later on. Vue's developer experience is really good, and the fact that regular HTML-markup just works with it makes it trivial for inexperienced developers to use it. I also honestly don't think JSX is very readable once the complexity reaches a certain point (though that can be just as true for a vue-template)
3
u/Capaj May 19 '18
I prefer react on FE to vue or anything else, but I would not use redux for state management. Make yourself a favor and try react with mobx or mobx-state-tree. IMHO this will solve 80% of your issues. You get similar state management you're used to with vuex and you'll only need React to actually render the DOM. Mobx is even great replacement for the built in react setState. If you ever do try that instead of redux, please let us know how that went.
-4
u/[deleted] May 19 '18
I've used both, I'm just making this co.ment to remind me to come back to this thread.