Why React? An AngularJS Dev’s Point of View

In my previous post about no longer supporting AngularJS, I discussed the following four points:

  1. It is opinionated, which doesn’t scale
  2. Angular (v2+) syntax is awkward and unnatural
  3. There are better ways of managing state than injectables
  4. It hampers talented developers, instead helping them

I believe the 4 points above make it relatively clear which framework I’m excited about. React does almost the opposite of each point.

React is non-opinionated

One thing that I have come to love about React is that, instead of having an MVC framework presented to you, you choose all layers that back the view layer.

There are some obvious decisions, like using a state management tool and an AJAX library like axios, but you could absolutely swap those out to meet your own needs.

I can admit to this leading to a little bit of decision overload up front. There is a lot that AngularJS presents a new developer with such as the $http service, the injectable architecture, form validation, data binding, and a slew of built in directives.

This is probably my biggest complaint about React, thus far.

It’s Javascript!

My second point around Angular (not AngularJS) is that the forced choice into Typescript and Decorator heavy syntax is a huge turn off for me. While I can appreciate the Typescript aspect, and have utilized it with success, having my hand forced in such a fashion is a shame.

The fact that DOM is generated by plain javascript is a huge win, but one that had me uncomfortable at first. Writing the DOM directly in a javascript class creates a very tight level of coupling that I’m not necessarily fond of. However, not needing to know what “item as item.label for item in $ctrl.myCollection track by $index” means is a huge win. Instead, I can simply do a map in plain JS. Beautiful!

State Management

I can understand some hesitation around a single application state. It’s monolithic, can be mutated by any piece of code that has access to the object reference, and can become unwieldy in the wrong hands. In addition, there’s a level of fore-thought required to really make something like a Redux succeed.

With that in mind, picture your first AngularJS app. How many services were injected into each controller? You had a UserService, AuthenticationService, $stateParams, plus all your model specific services. Heaven forbid, you also have third party services injected in the mix, as well. Now, imagine a use case that requires you to make a change to a critical function in one of those services. How many components & services need to be updated? My guess is a lot. The older an AngularJS application gets that relies on services for data management, the harder and more intertwined it becomes.

I find that React’s architecture lends itself well to maintaining good state management practices. Ensuring data is passed down and not back up (mirroring my data flow best practices blog a year ago) and also being able to enforce immutability easier because you’re not passing objects into angular directives that require the ability to mutate (ng-model, ng-repeat assigning $index).

Talented Developers Thrive

I will keep this section short, as it mirrors the first two points very closely. Due to the fact that React gets out of a developers way, it allows for them to move quickly. I find that the majority of my day in AngularJS land is spent trying to understand why something isn’t working, only to find it’s due to a quirk of the framework. I’ll be the first to admit, I haven’t spent enough time in React to be able to speak to React quirks yet, though.

A solid javascript developer can come from almost any framework and get working in a React codebase significantly faster than one can in an AngularJS app, and even faster yet than an Angular app. Learn typescript? Learn all of these extremely complicated decorators? Throw on top of that all the other aspects of AngularJS that carried over, and you’ve got one complicated mess to learn.

I will certainly write a follow up post as I move further into the weeds of React, but I am excited to move out of the AngularJS world after 5 1/2 years!

Front End Developer