r/angularjs • u/[deleted] • Jun 30 '18
Why React is bad.
Here's why I think Angular is much better than React for creating SPAs.
React is not a framework like Angular is. It doesn't provide a comprehensive, one stop solution for all the things that you need for building an SPA. Often you will hear that React is 'un-opinionated' and that it allows developers the freedom to use whatever technologies they want alongside it. In practise, this means having to either constantly reinvent the wheel, or else employ a hotchpotch of third party libraries and be completely at the mercy of their maintainers.
Third party libraries may be buggy and there's no guarantee that fixes will be swift, if they even happen at all. Plus, they may be deprecated without any notice and you have to hope that they will work together successfully.
For state management Redux is the defacto standard. Redux is, in my view, seriously flawed. Firstly, why do you need to have a store in your client side at all? Is that not what the Database is for? In an SPA, the URL should be the single source of truth and the entire state of the app should be derived from this, using data fetched from a service. When you use Redux in an SPA, you need to work to keep the store in sync with the URL. This is a lot of work for no obvious benefit.
Another problem is that it risks storing stale data. Once the URL changes, all the existing data is potentially stale. There is no value in storing data across requests. If you want to cache data, the browser will cache your requests. Invalidating caches is notoriously difficult to do - why on earth do we bring this problem to client side development!
Redux also introduces Race conditions. If we make multiple requests to the server in quick succession, the Redux store has no way of knowing in what order these were made and given that they can return in any order, it is quite possible that the page we are looking at could be overwritten by the data from an old request! More detail about this problem here:http://blog.richardhunter.co.uk/index.php/13
The Redux store does NOT represent the current state of your app. It probably contains it, but it contains an awful lot besides and working out what is the current state and what is old state involves a lot of error prone work.
The next problem with React is that it does not support Dependency Injection. https://en.wikipedia.org/wiki/Dependency_injection DI is essential for building a complex enterprise grade application. The main benefits of DI are that it makes object creation a much cleaner process and it decouples dependencies from their implementation. If the last point is unclear, what it means that when you build an object you can supply completely different objects for any particular dependency. This is useful in testing where you can swap in mock objects for dependencies and thus test your objects in isolation from each other. With React, you have to rely on monkey patching or else test much larger chunks of your code at a time.
In React, you have to pass any dependencies down to components through props which can mean that a component has props that it doesn't actually use itself but just has them so it can pass them down to child components. You can use the Context for surfacing dependencies in a component but this is very much a poor man's DI imho.
There are other things about React that I don't like, but I don't want to extend this post too much. In particular PropTypes seem like an extremely feeble way of doing static typing and really typifies what is bad about React.
React isn't just different for not being a framework - it's worse. It is hopelessly inadequate for doing the job that it is supposed to and just results in messy, buggy, and inadequately tested applications.
I think the reason that React is more popular than Angular is because Angular lost a lot of good will during the shift from version 1 to 2. Maybe the Angular team didn't cover itself in glory, but I think the decision was the right one as the new Angular is much superior to the old one. It's irrational to dislike Angular because of these events but maybe a lot of developers are irrational.
16
u/reboog711 Jun 30 '18
Have you ever looked in the node_modules directory of an Angular project? The last time I did it had over 400 directories. That is 400 different projects that my app depended upon.
I think your argument about about third party libraries is valid, however it is completely unrelated to React.
10
Jun 30 '18
The difference is that Angular is essentially a facade in front of all these Node modules. Angular is responsible for ensuring that they all work properly. If there was a problem with any one of them, that would be a bug with Angular and the Angular team would have to fix it. Compare that with working with React where you are responsible for researching the modules and libraries that you use and making sure that they all work together.
7
u/reboog711 Jun 30 '18
That's not true with the apps I build.
I have used a lot of external libraries that do not come directly from the Angular team--ng material, ng bootstrap, and ag-grid are a few more common ones. It is not the Angular teams responsibility to diagnose and fix bugs with these third party libraries.
15
Jun 30 '18
I read up until “why does your front end even need a store”... you have no idea man.
There are loads of reasons to persist data on the front end. PWAs not the least of them.
3
Jun 30 '18
PWAs use Service Workers.
4
Jun 30 '18
Sure does - but you still want to persist data so that the app works offline.
2
Jun 30 '18
Yes, that's what Service Workers do. https://developers.google.com/web/fundamentals/primers/service-workers/
7
Jun 30 '18
Ok, so you initially said you don’t think you should persist data on the front end, but now you’re ok with it?
2
3
u/ianwcarlson Jun 30 '18
A great example of needing to persist data in the frontend is a drawing app like draw.io. In other cases, it's about enhancing the user experience by reducing latency and spinning loaders every time they want to go from one page to the next.
3
6
u/zmasta94 Jun 30 '18
I think you're being overly harsh. I'm in the Angular boat but appreciate that React is sometimes the better answer to a lot of problems.
React probably has all, or most, of the issues you've mentioned above - but Angular has it's fair share too.
Totally agree with Angular losing developers after the migration. They really cocked that one up.
2
Jun 30 '18
They did. Angular2 should probably have had a different name. And they should have had a migration path defined right from the start. None of this though has any bearing on whether Angular 2 itself is good or bad.
4
u/DOG-ZILLA Jun 30 '18
Why would you say that you need to pass all this stuff as props down the chain when you also rant on about having a Redux store? That’s what a state management system can alleviate.
-4
9
u/ianwcarlson Jun 30 '18 edited Jul 01 '18
Most of the arguments against React are valid, but they ignore the advantages of React and are assuming the context is a green-field app. Angular is very opinionated and difficult to start incrementally introducing it into the frontend. There are still lots of Jquery apps out there. Using React makes the transition very flexible and easy.
Dependency injection has downsides too. In order to consume anything, like a third-party GIS mapping library for example, that isn't included in the canonical set, it needs to be wrapped in code to be consumable into the DI framework. This is potentially significant boilerplate to add if the app has dependencies that aren't included in the core libs. Since React just uses ES6 modules, most third-party libs are immediately consumable.
I think the argument about React devs having to piece together third-party libs has merit, but is overstated. React, Redux, React-router are pretty tightly coupled in terms of compatibility (React-router a little less so). Also, there is some really bomb-ass stuff like Jest, that you'd be missing out on if you're set on canonical.
React is the only major frontend library that puts HTML into Javascript. I can't stress how significant this is. All the other ones put JS into HTML. Doing it the non-React way creates custom DSLs that all have their own way of repeating a snippet of HTML or conditionally displaying something. JSX is just HTML folks. It's 99% faithful, just slightly syntactically different.
Because React is 100% JS, it's inherently capable of very powerful things: i.e., higher-order components or functions that return functions/components. HOCs provide a pattern for mixins, but also allows the code to bind values to a component via a closure so that code can be heavily re-used, and configured different during the bootstrap phase of the app. For example, you can configure HOCs to map to different parts of the Redux state without modifying the HOC itself. This is very useful for reusable components that store state in Redux.
I actually generally agree with your arguments about React and Redux, but I don't think you provide the full picture. Lots of apps aren't green-field. This is where a incremental transition to something else is easier with less opinionated libraries.
All major frontend frameworks are very capable of building a solid, maintainable UI. Whenever someone tells me they're rewriting their entire frontend from Angular to React (or vice versa) I cringe. To the users and the stakeholders, the framework doesn't matter, but spending 3 months not pushing features does.
Edit: grammar
3
u/XPTranquility Jun 30 '18
Just here so I won’t get fined.
0
Jun 30 '18
[deleted]
4
u/akujinhikari Jun 30 '18
Just want to echo that IF React is faster, it’s insanely marginal. I’ve seen a lot of benchmarks for different versions, and some comparable versions of Angular were faster than React. But even then it was insanely marginal. I don’t know where this myth started, but its empirically false.
1
Jun 30 '18
Yes, the problems of race conditions can be solved by writing more code: That's called 'bug fixing'. Nor does Redux advertise these problems, and in my case I only learned about them when I encountered them myself. Redux Observables are the solution imho. Angular of course is built with Observables tightly integrated into it. Apparently the Angular team understand this problem and have picked the correct solution.
Your arguments about performance boils down to: React is fast and Angular is not. But that needs some serious metrics behind it for it to be true. There have been numerous performance comparisons carried out on React and Angular and I've yet to see any conclusive evidence that one is dramatically superior to the other in terms of performance.
4
u/prof_hobart Jun 30 '18
So the issue here seems to be that you once used Redux, didn't know how to deal properly with async requests, created a bug in your code and blamed Redux for not holding your hand enough.
As I've explained elsewhere, there's plenty of well worn approaches that don't need observables to solve the problem.
Observables are find, and the fact that Angular provides a lot of this out of the box rather than you having to think about it yourself is great for some people.
But for others, the flexibility of approach that you get when you piece together a React-based solution is also an advantage.
1
Jun 30 '18
No, you can use Redux exactly as recommended in the docs and have this bug. The problem is known about by Dan Abramov himself and he suggests ways to overcome it. The point is, this bug shouldn't be there to start with. https://stackoverflow.com/questions/37738268/how-to-avoid-race-conditions-when-fetching-data-with-redux
6
u/prof_hobart Jun 30 '18
Yes. That would be a pattern for dealing with async. It's not a bug that a particular library doesn't do that magic for you - it only becomes a bug if your code doesn't then add the magic that your chosen library didn't (As Dan said "The problem is due to suboptimal state organization.")
You can argue that library A might be better for you than library B because it makes easier for you to implement a particular pattern, but that's vastly different from claiming that it's a bug in library B because it doesn't do it - if that's not part of library B's remit, it's just up to you to add it yourself.
-1
Jun 30 '18
Dan's solution doesn't actually remove the problem, it only mitigates it. I disagree with Dan's assertion that if his library doesn't work then it must be your data model that is wrong. Why should the structure of my data have anything to do with whether or not I get a race condition?
As far as I know, the issue isn't flagged anywhere in the Redux documentation (such as the 'Troubleshooting' section?) so it is sitting there waiting to bite someone. The idea that not being able to handle responses coming back out of order is some kind of marginal concern seems strange to me.
5
u/prof_hobart Jun 30 '18
Redux isn't there to solve that specific problem, so why should its docs cover it? Its docs aren't an essay on computer science as a whole, and it's assuming that you've got a fair amount of experience in this kind of thing.
You seem desperate for a one-stop shop framework that spoon-feeds you all of the answers - which is fine, if that's where you are on your professional journey.
But many of us want more flexibility, and realise that this sometime means that we have to do a bit of our own thinking about some of the thornier problems of computer science.
The idea that not being able to handle responses coming back out of order is some kind of marginal concern seems strange to me.
The problem is potentially that you've designed a system where there is such a thing as "out of order" - in most cases, if you're kicking off multiple simultaneous requests, it shouldn't matter what order they come back in.
In situations where it is an issue, there are standard ways to deal with it - which one to pick depends on the nature of the data you're getting back - whether you're cancelling/ignoring the latter responses, overwriting a particular bit of data, checking timestamps etc.
But the point is that you actually need to think about it - the framework isn't going to magically make that decision for you, as it doesn't know your data. It might make some of those solutions easier to implement, but if you're just looking at the framework to solve it for you without doing the thinking yourself, you've got a fair chance of it making the wrong decision.
-2
Jun 30 '18
if you're kicking off multiple simultaneous requests, it shouldn't matter what order they come back in.
So if the user clicks a button for 'page1', then changes their mind and clicks the button for 'page2' and page 2 appears but is shortly overwritten by page1, that's ok?
2
u/prof_hobart Jun 30 '18
No. Why would it be? And what's this got to do with React or Redux?
→ More replies (0)2
Jun 30 '18
That has little to do with redux... and everything to do with how you manage async requests.
1
Jul 04 '18
Could add to this that PropTypes as a form of Static Type checking are laughable when compared to the equivalent in Angular/Typescript. So embarrassed by them were the React team that they removed them from the core module.
1
Jul 07 '18
Another problem is that action types are global variables. You need to be careful not to duplicate the name of one. You need to have a good naming convention in place right from the start that is going to be able to cope when your app scales. If the naming convention no longer makes sense when the app scales, refactoring is a huge pain in the ass.
4
4
u/PostHumanJesus Jul 01 '18
I'm feeling compelled to comment as I think you are borderline spreading misinformation/treating opinion as fact.
Different teams/devs/apps have different needs and use cases. If something works better for you/team/app then that's great. Most of your cons can/have been refuted and can be pros to others.
If you don't like, don't use it. If you think it's harmful to the JS community then learn more about it before bashing. It works fantastically well for lots and lots of teams/apps/companies... So does Angular.
1
u/joesb Jul 01 '18
I could agree with you that React not being full framework comes with some downside. But that is just trade off that is subjective.
The rest, though, is stupid and short sighted. It’s almost like you haven’t wrote a real application at all.
“Source of truth should come from the backend/URL”? This is so naive it hurts. Are you gonna keep all application on the server? Every single item selection? Every keystroke?
Is your app gonna need internet connection all the time?
How do you handle complex editing on client side? Do you ever have UI specific state in your app at all?
“React doesn’t support dependency injection” is also misleading and contradict your previous statement.
“React is not a framework” remember? It neither does or does not support Dependency Injection. It doesn’t prevent you from using DI in anyway.
Please learn to be informed before being a fanboy.
-1
Jul 01 '18
You might want to address my points rather than just lashing out with insults. It doesn't reflect well on you. Particularly since I haven't said anything against you.
1
2
u/crashuniverse Jun 30 '18
I use React and lot of things you mention like Redux, not being a one stop solution and popularity isn't much of a strong differentiator. React did provide very early solutions on server render and simple APIs that shaped front end community forward. The choice is often well suited also on comfort level on the involved team besides features. Your points makes Angular great, not necessarily React bad.
4
u/SparserLogic Jun 30 '18
It's weird reading a list of things portrayed as negatives where all of which I have long viewed as positives.
Your first point alone is enough for me to never recommend or want to work with angular again.
Please spare me the dictatorship of a framework that thinks it knows best.
0
u/akujinhikari Jun 30 '18 edited Jun 30 '18
I haven’t used React more than a beginner’s tutorial, but as soon as I started writing JSX, I said I never wanted to work with React again. That being said, I can’t offer any support for why you don’t like it, but I have worked extensively with Angular, and if all your points about React are valid, then I am so glad I stuck with Angular. All that stuff is so well-integrated into Angular, that it’s easy to take for granted. Thank you for allowing me to appreciate it even more, and also wonder why it gets so much hate in this sub.
1
Jun 30 '18
My theory is that developers don't like Angular because they are upset about what happened to Angular 1. In every conceivable way it is obviously superior to React - except in performance where they are probably about equal. I think Angular will push on this year. Observables and DI are just such killer features.
2
u/akujinhikari Jun 30 '18
Honestly I think what happened is that Angular integrating Typescript and RxJs made the learning curve pretty steep, so people just said, “Ehhh it’s slow” and moved to things that are much easier to learn: React and Vue. The problem is that now Angular has this stigma that it’s slow, but as you said, its performance is basically the same as React’s. And now people are hailing Typescript and RxJs as awesome libraries, so I continue to wonder why people keep hating on Angular. It’s like the PHP of JavaScript. People make fun of it just because it’s the cool thing to do, instead of actually learning about it.
2
1
u/xWalrus11 Jul 03 '18
Angular had a horrible PR start which put it way behind React. But now Angular can do everything React can do and React can do everything Angular can do, it just comes down to developer preference.
3
1
-2
25
u/prof_hobart Jun 30 '18
A client-side cache is there to improve performance - faster client responses, less server load and less fragile to intermittent networks. If you don't need any of that, you possibly don't need a client cache. There's absolutely nothing in React's structure that prevents you pulling the required state from the server on ever page navigation. And there's nothing to stop you using the browser cache if that's what you want to do. But that's a lot more complex than simply building up a client-side model of the data your app needs.
If you're doing multiple async calls at the same time that can return contradictory data, then yes this is something you're going to deal with. But I'm not sure how that's got anything to do with React - it's been true as long as I've been working on async. There's things that you can do to help, but again mostly nothing language-specific, such as
redesign your system so that you don't have this possibility (it's the kind of thing that backend-for-frontend orchestration tiers are there to help with - create a single server-side endpoint that pulls data from multiple sources and returns it in one go)
have your client-side logic know which data should take precedent, whether based on which call it was, what the timestamp of the call was, or something else
wait for call A to come back before kicking off call B
There's things that libraries can help with (redux-saga, for instance, makes some of the coordination easier), but fundamentally these are just basic problems of asynchronous traffic - if you do two simultaneous calls, you've got no direct control over what order they'll come back in. Or is there something magical that Angular does to make this go away?
Don't understand what you mean. If you're designed your model badly, or don't understand the nature of your server interactions, then yes you're going to have problems. But in a well-designed app, this is one of the things that Redux makes ridiculously easy - take the current state and apply a transformation to it based on the most recent action and produce a new state. It's basically functional programming, making it easy to both reason about and test.
This is one of the other things that Redux makes very easy - at the appropriate point in your component hierarchy, pull out the bits of state (and potential actions) that it needs to worry about and pass them as params.
It doesn't have a whole framework around dependency injection, no. But there's nothing stopping you simply injecting your dependencies through parameters if that's what you want to do.
There's plenty of problems with React. But most of these seem little to do with React at all and the ones that do seem to be based on a flawed understanding of what it provides.