Why React is the best out of three frontend libraries/frameworks

Jul 1 · Unlisted

So you’ve started going through some front end techniques, and you’ve been exposed to these things called React, AngularJS, and Backbone. Maybe you’ve got certain opinions on each and you (probably) have a favorite. Well, I’m here to tell you, React is best. Get ready for a three minute read of my opinion on the matter.

React wins on the internet

The above chart clearly demonstrates that most people prefer React over Angular. I’m not even going to throw Backbone into the conversation just yet because it’s 2019, not 2009. The most important are the two columns on the left. The blue one shows that nearly 65% of people who used React would use it again, as compared to nearly 24% of people who would use Angular again. The second column is even more damning, as only 7% of people would NOT use React again, and a whopping 34% of people would NOT use Angular again.

So it’s not just me, guys. The consensus is that React is better than Angular (and they’re BOTH better than the outdated Backbone). But why? In my case, it’s all about how data gets passed around. In React, we have these things call props, which are kind of exactly what they sound like — they get passed around like properties in functions. Take the following code example:

Passing data around in React is easy as pie

On the left, we have an index.js file — the entry point for the whole app. On the right is a component file that we would like to pass the variable fishData into. So, on line 23 of the index.js file, we simply call the FishTable constructor, and give its props an the fishData array. Props itself is an object, so over on line 1 of FishTable.js, we can just use ES6 deconstruction inside the parameters to grab that fishes object and make it available to our entire function. Not only that, but JSX makes it SOOOO easy to write normal JS, the stuff we’re comfortable with, inside our HTML. All we have to do is wrap our JS in curly braces, as on line 4 where we’re using a regular map function. All that being said, if you’re comfortable with JavaScript, React makes your HTML and frontend functions work just like you’re used to functions working.

Now, let’s check out this SAME EXACT thing in AngularJS:

Passing down data in Angular is….complicated.

So here we’ve got the same data, and would like to do the same thing — namely, pass fishData from main.js to fishTable.js. Right off the bat we can see the code is more complicated, especially on the left. Rather than just calling ReactDOM.render(), we have to create a “module” and attach a “component” to that module, which then has a “controller” attached to it, along with a “template” of HTML. While this is certainly not too difficult to figure out, after seeing how React does it, AngularJS just seems so silly — it’s no wonder Google has abandoned it. But more to the point — how is it passing the fishData down? Through the actual HTML in the template on line 26 of main.js. It has to first put that data on the “controller”, then it can pass it though, similar to props in React. Not too bad huh? Wait til you get to the fishTable file. Bindings? What the hell is that? That’s how AngularJS expects you to tell it that it should be accepting data from a parent. It doesn’t just happen like you’d think. Not only that, but even though we pass down data through HTML, we can’t use JavaScript to do that. There is no JSX here, no way of telling our code, “hey read this as JS, not HTML.” So we have to use Angular’s directives, which are special keywords like ng-repeat on line 11 of fishTable. It’s highly annoying and feels much like learning an entirely new language just to use a framework.

So that’s it. Passing data around, the core of programming, is easier in React — which means React is better. The end.

Unless, of course, you’re stuck having to choose between AngularJS and Backbone (for whatever ludicrous reason). Then go with AngularJS, every time. The ONLY time to use Backbone is if your company tells you they’ll fire you if you don’t.

Unlisted

Clyde Bates

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade