React vs. Angular: A Popular JavaScript Library and a Powerful JavaScript Framework

The main differences between AngularJS and ReactJS have to do with componentization, data binding, performance, dependency resolution, directives, and templating.

Most interactive single-page applications are built with the help of JavaScript (JS) frameworks and libraries. The number of JS tools for fast single-page application (SPA) development is constantly growing, making the choice of which technology to rely on more challenging for us as web developers. computer science course computer science jobs computer science binus

Both React and Angular are currently used by many business, news, and travel companies in the USA, the UK, Canada, France, Germany, Australia, and other countries. AngularJS has been included in virtually every list of top 10 JavaScript frameworks since its release in 2009. computer science course computer science jobs computer science binus

This Model-View-Controller framework has become extremely popular among web developers. ReactJS is even more widely used by JavaScript programmers, although it’s actually a library, not a framework; the React library only has a View, but lacks Model and Controller components. So, how did React became so popular, and how can we reasonably make JavaScript frameworks comparisons compare a framework (AngularJS) with a library (ReactJS)? computer science course computer science jobs computer science binus

The main differences between AngularJS (the framework) and ReactJS (the library) are in the following aspects: componentization, data binding, performance, dependency resolution, directives, and templating. Let’s look at each of these aspects separately. computer science course computer science jobs computer science binus

Componentization

AngularJS

AngularJS has a very complex and fixed structure because it’s based on the three layers — Model, View, and Controller — typical of single-page applications. An object $scope in AngularJS is responsible for the Model part, which is initialized by the Controller and then transformed into HTML to create the View for the user. Angular provides many standard services, factories, controllers, directives, and other components that will take some time for a JavaScript developer to master initially. computer science course computer science jobs computer science binus

With AngularJS, we break the application code into several files. For example, when we create a reusable component with our own directive, controller, and template, we must describe each chunk of code in a separate file. Once we describe our directive, we then add a link to our template in the directive to couple these parts. AngularJS directives represent the template logic for your application. The template is HTML extended with Angular directives, generally written as tags or attributes. We also add controllers to provide our models with necessary $scope or context. Controllers are written in separate files as well. When we modularize our application in such a way, we can reuse our template or component in a different part of the website. computer science course computer science jobs computer science binus

ReactJS

Facebook, the creator of ReactJS, chose an architecture different from that of AngularJS and similar MVC frameworks. In short, there is no “correct” structure for applications built with ReactJS. computer science course computer science jobs computer science binus

ReactJS is a large JavaScript library that helps us update the View for the user. But ReactJS still doesn’t let us create applications on its own. The library lacks the model and controller layers. To fill in the gap, Facebook introduced Flux, which has numerous variants nowadays, to control the application workflow. computer science course computer science jobs computer science binus

ReactJS provides a very simple and efficient way to build component trees. It boasts a functional programming style where component definitions are declarative. Composing your app from ReactJS components is like composing a JavaScript program from functions. Just look at the example below, taken from GitHub: computer science course computer science jobs computer science binus

var TodoApp =React.createClass({
getInitialState:function () {
return {
nowShowing:app.ALL_TODOS,
editing:null,
newTodo:''
};
},
handleChange:function (event) {
this.setState({
newTodo:event.target.value
});
}
});
// other code is omitted for brevity

Code written in ReactJS is logically structured and readable thanks to the availability of components. The ReactJS library doesn’t demand that you write code in a certain way. They suggest that you use JSX (a special XML-like syntax) to create classes and templates, but it’s also possible to write plain JavaScript and HTML. This helps JavaScript developers adapt to React applications more easily, as there is no unusual syntax to learn. React offers a freedom that AngularJS doesn’t. But this freedom comes at the cost of additional time spent designing the structure of an application. Before we start a new project, we have to think about what instruments we are going to use. When you have to pick a tool from among 100 options to resolve a single task, this choice becomes cumbersome. computer science course computer science jobs computer science binus

Prev1 of 5Next

Leave a Reply

Your email address will not be published. Required fields are marked *