Sunday, May 10, 2015

React over Angular - my take

I took some time to learn React JS in the last few months. I created my little version of todomvc like application, created the same application using React and using Angular. The code lives here:

react-prototype
angular-prototype

Here is what I found. Overall I liked React much more than Angular for the following reasons:

  1. My debugging experience was much better. Angular brings JS into HTML and React brought HTML into JS. At first I cringed a little at the thought of having HTML within JS. As I kept building the application though it was much easier to debug issues. 
    1. First things first -- there was only one file to look at. Nothing more. All my JS and HTML is within one single file. Unlike Angular JS where I had to look at a directive, an HTML and a controller.
    2. JSX caught a lot of errors at compile time. This gave me more confidence. With the angular app I found errors at run time AND after a few hours of that error introduced.
    3. Easier to refactor - The above reasons made it easier to refactor the code as well.
  2. Componentization came naturally. With this I mean creating web components that can be distributed and reused much more easily. Again - having a single file helped a lot. I will be writing more about componentization in later posts.
  3. React definitely had a very small learning curve, much smaller than angular. It was much easier to explain React than Angular to my friends who knew nothing about both.
  4. Aligns well to Page Object pattern that is popular in testing circles. Although this is not the best of the reasons - it is worth a mention.
  5. The idea behind React makes complete sense. The part that model is the state and HTML is the projection of state and that only part of HTML that has changed is the one that is modified.
So - would I use React on my next project? This is a difficult question to answer. I would certainly advocate for it. A lot depends on the organization / project though. If there are Angular / any other framework experts out there and things are done well - there is no need to rock the boat.