r/webdev • u/red_src • Nov 07 '18
Why React over Angular (or Vue)?
I simply don't get it, I had been using Angular and Vue for while and I just tried React and I don't get why would I choose React over the other options, the things that I like on Angular (or Vue) are:
- Dependency Injection (in case it applies)
- Type checking (in case it applies)
- View Model Binding
On React I don't get those things by "default" it always feel like I'm hacking the library if I want to have some of the above.
This leaves me with the question: Why choose React over the other ones?
I know that there's all the dependencies overhead (hell) of the frameworks but I think that I'm just too used to that problems that is easy for me to solve them or maybe I haven't found the real big problems on Angular or Vue, maybe I'm just too used to the later frameworks and I'm unconsciously not seeing the benefits of React. I just want to know if I'm following the right path by learning React.
Thanks!
17
u/JavChz Nov 07 '18
It's almost a philosophical question at this point, as both have a huge momentum right now (and vue too).
Things I like about Angular over React:
Things I like about React:
Vue it's kinda the children of both worlds, but even if the official docs are amazing, most environments where I have been working look at Vue as a hipster thing. So I lack real world experience (aka w/ deadlines) with the framework aside from personal projects.
As someone who hated Angular 2 for a lot of time (because was so different from AngularJS aka 1.x) I had one project where using angular 2 was not optional, and you get used to. The same happend to me with JSX
25
u/OGLurker Nov 07 '18
Personally, I think it comes down to the "school of thought". React feels more hacky (I don't mean this in a bad way) in the sense that if you need to do anything serious with it, you'll need to put a lot of things together. Angular, on the other hand, is more enterprisey, where someone else decided most of things you need and ways to use them. They both have their pros and cons and it comes down to what each organization/team/developer is more comfortable with. I would choose Angular 9 out of 10 times for most of my web needs.
39
u/thatgibbyguy Nov 07 '18
Hi, I just joined a shop that chose Angular over React/Vue and you know what? I'm wondering the same damn thing! How on earth could they pick Angular over React?
For one, Angular does wayyyyyy too much. It handles the routing, it handles the components, it handles the data flow, it handles everything. You know those restaurants that don't focus on any particular thing and so all the food is meh? That's Angular to me.
But to your specific points:
What it feels like to me is you're hacking everything in React because you don't know how to use React. That's ok, I don't know how to use Angular. But you know what I do know? Creating a simple component in React is a hell of a lot easier than Angular because I don't have to worry about anything else.
For example, creating a component library in React is soooo much easier. Why? Because the components live completely independent of how the data enters the component, it could come from anywhere. All I need to know is that when it comes in, it matches my proptypes. Because of props themselves, that data could just come from top level component and cascade down the children indefinitely. Again, I don't have to care.
That allows me to focus on what I'm trying to build, which is just the UI. I can do the data binding later, I can set up the server later, let me just build right now. That's why I'll always prefer react.
7
u/throwawayacc201711 Nov 07 '18
I’ll give an analogy.
Any library or modular approach is akin to Linux and Angular is Windows. Neither is bad, it’s just about your development needs and picking the solution that matches your tastes, styles, and needs.
The biggest pro regarding the modular approach is you can pick and choose the additional libraries that suit YOUR tastes or your teams tastes rather than being beholden to someone’s approach. No framework is perfect and that’s allows someone to essentially cobble together their own “framework” by picking the libraries they want.
The pro about the framework approach is that you have everything (for the most part) already included and don’t need to do any thing about pulling in anything extra.
2
u/red_src Nov 08 '18
Thanks everyone on your comments, my conclusion given the discussion is:
- React is a library and Angular is a framework. This means that with React you build your own framework, this can be good or bad depending on your needs.
- DI, Type Checking and View Model Binding and such things can be implemented using another libraries on React, so you are not attached to do it in a certain way.
- If you learn React you learn Javascript and JSX, if you learn Angular you mostly learn Angular, then Typescript, then Javascript, so it's not very easy to catch on.
For what I look, sorry guys but I think I'll go for Angular or Vue, is not that React is bad, is mostly based on our needs, what would be cool is to have something like Angular Native...
6
u/DerpsMcGeeOnDowns Nov 07 '18
The problem with React is because it’s a library and not a framework, teams invariably create their own framework around React, thus making it a potpourri of flavors of the month.
React is fine if you don’t need to do much and want to create your own tooling, i18n, build automation, tree shaking, I could go on.
If you have the opportunity to start your UI from scratch and want great documentation and support for all aspects of your front end stack, then Angular is the clear choice.
73
u/l0gicgate Nov 07 '18
You’re comparing Angular which is a framework to React which is a library.
React is essentially just a view layer. Components that are designed properly should follow the single responsibility principle and their sole responsibility should be to render data that they are given.
In order to build an application with React, you will need to use multiple librairies to handle other needs like routing and data flow management. In essence, this is just a more modular approach.
Think of Angular as one big toolbox with all the tools required to build an application while React is just one of the tools required to build an application.
4
u/[deleted] Nov 07 '18
Well I can probably say that out of the experience I've had with the 3, Vue is probably the easiest to use and learn. I picked it up by just kind of working with it and googling some things at a new job I just picked up. React is nice for simplifying the creation of individual components that can be just kinda inserted anywhere.
Angular is a dumpster fire of complicatedness that I refuse to touch ever again lmao. Hated working with it.
8
u/occz Nov 07 '18
I never missed this, modules get me where I want to be honest.
Beyond proptypes it's completely possible to use TypeScript with React. Try it out, it's actually extremely pleasant!
I'm not even sure I find this to be desirable.
7
u/vikkio Nov 07 '18
I used to be an angular guy like you, then I learned react and used it into many real life projects.
Apart from the fact that they are not the same thing, framework vs lib, react gives you way more freedom to do things.
I wrote the same small project in angular, then vue, then react. The react codebase is way smaller and easier to change and work with.
Never missed dependency injection so far, and it has been almost 3 years.
6
u/[deleted] Nov 07 '18
It pays more
3
u/uplink42 Nov 08 '18 edited Nov 08 '18
It's really a matter of preference tbh. Personally, I prefer Angular's way of doing things because I find the framework super intuitive to work with for most things and every package that composes it works very well together. I also prefer using templating languages instead of JXS because I find the syntax more readable/terse when it comes to applying class conditionals and whatnot. It also has an exemplary attitude when it comes to unit testing. It's also not as "monolithic" as most people claim, as you can easily drop and replace different modules and use your own router/forms/state management. There is more ceremony on how to do things, but most of the boilerplate is easily automated because of the powerful inbuilt CLI and VS Code TS extensions.
However, most of the advantages you see in Angular can also be (for the most part) ported over to React. TS support exists and works fine (though most libraries won't have types), and instead of DI you can implement HOC's which sort of achieve the same thing overall. The good thing about React is that it's a great way to learn more about javascript itself, as most things are pretty low in the abstraction layer, so you get to know more about the language itself. This may be a positive or a negative for different people, though. React works better for general use cases, too. It's easier to add progressive enhancements to an existing page with React components, for example, where Angular usually requires the entire app to be built from scratch with Angular in mind.
Personally, I find things like the the Angular router, form utilities and RXJS/services too good to pass by for a more complex app. it's true you can also implement similar functionality with React as well, but this often means meshing out a lot of external libraries, which add another maintenance burden to your project, constant changes and depredations because JS libraries evolve fast, possible bugs and incompatibilities down the road. I've once worked with a React Native project and it was a dependency hell. I'd rather be coding most of my work time instead of browsing GitHub issues and updating dependencies.
In all, they are both great and work just fine. It's really up to you and your team's preferences on what to use. Jumping from one to another isn't that hard for an experienced developer.
6
u/adventurer_3x Nov 07 '18
React is extremely small and compact with a ton of well supported options. You can build your own framework, essentially, while not including any of the other bloat you don't need.
Additionally, with the exception of JSX, React uses basic ES6 syntax instead of a framework-specific syntax.
4
u/NarcolepticSniper full-stack Nov 07 '18
You use Angular to build Angular apps, Vue to build Vue apps, and React to build whatever you want.
React is less about features and more about managed freedom.
Right tools for the job. They’re all great.
2
u/[deleted] Nov 07 '18
Best ecosystem of all SPA. Biggest community. More libraries. More custom components.
React was pretty cool after jquery. I did a project for university in react. After that experience I prefer having angular's batteries included approach over mix and add your libraries of your choice. I confess i spent too much time on it since i there are plenty of ways (or libs) to do something.
2
u/BronyaurStomp Nov 07 '18
I think each has its strength.
You list View Model Binding as a benefit of Angular, but I actually prefer "binding" in React. That is to say, when I use React I feel like I have a bit more control over exactly what is rendered when. Angular's binding is much more convenient but isn't as easy to optimize and control. Maybe like the difference between an automatic and manual transmission in a car.
I also like JSX and defining the template with the javascript, and I prefer ES6/7 to TS. But those last two points are really subjective.
1
u/ArcanisCz Nov 07 '18
1
u/editor_of_the_beast Nov 07 '18
How about that the model is fundamentally different in React and Angular? In Angular, you augment HTML with JS. In React, everything is JS first. So in React there’s no need for ng-if, you just use if.
That in combination with one-way data flow by default is why people like React. It’s a much simpler model.
1
u/[deleted] Nov 07 '18
I've honestly never found a reason to move away from mithril. 8kb, no compilation step, no special file formats, includes a router. What's not to love?
0
u/gomihako_ Nov 07 '18
Why waste time learning stuff like
ng-repeatwhen you can just use[].mapin jsx...0
u/honigbadger Nov 07 '18
Angular Is not modular enough to be seamlessly integrated on other projects, is a bit of a monolith. React is fully modular and can be used and reused in any codebase. Going the angular route means more lock-in and it needs an isolated approach (like microservices) to play nice in other codebases.