React vs Angular, who is better?

In the field of programming, Angular and React are currently the two most popular Java frameworks for front-end developers.

Whether in terms of popularity, architectural similarity, or from a Java-based perspective, these two front-end frameworks have many similarities.

In this article, we will make an in-depth comparison between React and Angular. We will start with the basic characteristics of the two frameworks.

A brief introduction to Angular and React.js

Angular

Angular is a front-end framework supported by Google. It is compatible with most commonly used code editors. It is part of the MEAN stack.

The MEAN stack is a free and open source, Java-centric tool set that can be used to build dynamic websites and web applications.

Its components include: MongoDB (NoSQL database), Express.js (Web application framework), Angular or AngularJS (front-end framework), and Node.js (server platform).

The Angular framework allows developers to create dynamic single-page Web applications (Single-Page Web Applications, SPA).

The original version of Angular solved the problem of converting HTML-based documents into dynamic content.

Here, we will focus on its newer version, Angular 2+, and the difference between it and AngularJS.

In industry cases, Angular is mainly used by Forbes, WhatsApp, Instagram, healthcare.gov, HBO, Nike and other organizations.

React.js

React.js is an open source Java library created by Facebook in 2011 to build dynamic user interfaces.

React is based on Java and JSX, and JSX is a PHP extension developed by Facebook that can create reusable HTML elements for front-end development. React has an independent cross-platform framework React Native that can be used for mobile development.

In industry cases, React is mainly used by organizations such as Netflix, PayPal, Uber, Twitter, Udemy, Reddit, Airbnb, and Walmart.

Tool set Framework vs Library

Readers with development experience know that the framework ecosystem defines the seam less of the engineering experience. Next, let’s take a look at the main features of Angular and React.

First of all, React is not a real framework, it is actually a library. Therefore, it requires multiple integrations with other tools and libraries.

In contrast, when using Angular, you already have all the conditions for building an application.

Image for post
Image for post

Angular provides the following out of the box functions:

  • RxJS: It is an asynchronous library that reduces resource consumption by setting up multiple data exchange channels. The main advantage of RxJS is that it can handle events independently and synchronously. However, the accompanying problem is: Although RxJS can work with many frameworks, you must learn about the library to make the most of Angular.
  • Angular CLI: With a powerful command-line interface, it can assist in creating applications, adding files, testing, debugging, and deployment.
  • Dependency injection: This framework separates various components from their dependencies and makes them run synchronously; at the same time, they can also change dependencies without reconfiguring components.
  • Ivy renderer: As a new generation of Angular rendering engine, Ivy’s performance has been significantly improved.
  • Angular Universal: It is a technology used for server-side rendering. It can quickly render the first application page or display the application on a browser-side device (such as a mobile device) that may lack rendering resources.
  • Aptana, WebStorm, Sublime Text, Visual Studio Code: are common code editors for Angular.
  • Jasmine, Karma, and Protractor: All are tools for end-to-end testing and debugging in the browser.

React requires multiple integrations and various support tools to run:

  • Redux: It is a state container that can accelerate the running of React in large applications, manage application components with a variety of dynamic elements, and can also be used for rendering. In addition, React uses a broader set of Redux tools, including: Reselect, Redux’s selector library, and Redux DevTools Profiler Monitor.
  • Babel: It is a conversion compiler that can convert JSX into a Java application that can be understood by the browser.
  • Webpack: Since all the components are written in different files, we need to bundle them together for better management. And Webpack is a recognized standard code bundler.
  • React Router: This router is a standard URL routing library often used by React.
  • Similar to Angular: You are not limited in terms of code choice. Its common editors include Visual Studio Code, Atom and Sublime Text.
  • The difference with Angular is that in React, you cannot use a single tool to test the entire application, but you must use different tools for different types of tests.

The following is a list of how React works with various tools:

  • Enzyme and Unexpected-react are used for component testing.
  • Jest is used for Java code.
  • react-testing-library is used for React DOM testing.
  • React-unit is used for unit testing.
  • Skin-deep is used for rendering tests.

The Chrome Extension and Firefox Extension of React Developer Tools, and React Sight can also visually display the status and prop tree.

Both of these tools form a strong ecosystem. Under normal circumstances, users tend to choose React, but React needs a variety of integrations such as Redux to expand its service capabilities.

Component-based architecture: reusable and maintainable components of two tools

Both frameworks have a component-based architecture. This means that a single application can build a variety of user interfaces through modular, cohesive, and reusable components.

In Web development, component-based architecture is generally considered easier to maintain than using other structures.

It speeds up the development process by creating separate components, and enables developers to shorten the time for products to go online, and to adjust and extend applications.

①Code: Type vs Java (JSX)

Angular uses the Type language (of course you can also use Java if needed).

Type is a superset of Java suitable for large projects. It is both compact and able to recognize errors in input.

Other advantages of Type include: better navigation and auto-completion, and faster code refactoring.

In addition, Type’s scalability and simplicity are also very suitable for large-scale projects on an enterprise scale.

React uses Java ES6 and JSX scripts. JSX is a syntax extension of Java that is used to simplify UI coding and make Java code look more like HTML. JSX can not only detect various errors, but also protect the code from injection attacks.

In addition, Babel (https://babeljs.io/) uses JSX for browser compilation. Babel is a compiler that converts code into a format that can be read by a web browser.

Although JSX can almost achieve similar functions to Type in terms of syntax, some developers still think it is more complicated and difficult to learn.

②DOM: real vs virtual

The Document Object Model (DOM) is a programming interface for HTML, XHTML or XML documents.

It has a tree-shaped organization structure that enables scripts to dynamically interact with the content and structure of Web documents and update them.

There are two types of DOM: virtual and real. In terms of implementation principle, even if one element changes, the traditional or real DOM will update the entire tree structure.

The virtual DOM is a mapping of the real DOM, so it only tracks the changed parts, only updates specific elements, and does not affect other parts of the entire tree.

Image for post
Image for post

React uses a virtual DOM, while Angular runs on the real DOM and uses change detection to find components that need to be updated.

Although virtual DOM is considered to be faster to operate than real DOM, in Angular, due to the need for change detection, these two methods are actually equivalent in terms of performance.

③Data binding: two-way vs down (one-way)

Data binding is the process of synchronizing data between the model (business logic) and the view (UI). There are two basic implementations of data binding: one-way and two-way. The difference between one-way and two-way data binding lies in the update process of the model view.

Image for post
Image for post

Two-way data binding in Angular is similar to the “Model-View-Controller (MVC)” architecture,

Since the model and view are synchronized, changes in data will affect the view, and changes in the view will in turn trigger corresponding changes in data.

React uses one-way or downward data binding. The one-way data flow does not allow the child element to affect the parent element when it is updated, so it is guaranteed that only approved components will change.

It can be seen that this type of data binding makes the code more stable, of course, it also requires additional work to synchronize the corresponding model and view. After all, it takes more time to update the configuration of the parent component triggered by the child component change.

In general, React’s one-way data binding is more predictable, the code is more stable, and debugging is easier. The traditional two-way data binding in Angular is easy to use.

④ Application size and performance: Angular is slightly better

AngularJS has lower performance when dealing with complex and dynamic applications. And because of the use of virtual DOM, the efficiency of various React applications is faster than AngularJS applications of the same size.

In addition, the study also shows that: Angular’s application size is slightly smaller, the transfer size (Transfer Size) when tested is only 129 KB, while React + Redux has 193 KB.

Image for post
Image for post

⑤Pre-built UI design elements: Angular Material vs community-supported components

Angular: With the popularity of the Material Design language in web applications, more engineers benefit from its out-of-the-box material toolset.

Angular has pre-built material design components. Its Angular Material can implement a series of common interaction models for form controls, navigation, layout, buttons, indicators, pop-up windows, modules, and data tables. Due to the existence of various pre-built elements, the speed of configuring the UI becomes faster.

React: Most of its UI tools come from its community. Currently, the UI components section of the React portal (https://reactjs.org/community/ui-components.html) provides a large number of free and partially paid components.

You need to install the Material-UI library and various dependencies to build using React’s material design.

In addition, you may also use the Bootstrap components built by React (https://react-bootstrap.github.io/), and include UI components and toolsets (https://hackernoon.com/23-best-react- ui-component-libraries-and-frameworks-250a81b2ac42) other software packages.

⑥Mobile portability: Native vs React Native

Both of these frameworks come with tools that allow engineers to port existing Web applications to mobile applications.

We also conducted an in-depth analysis and comparison of Native (Angular) and React Native.

Here is a brief summary of the main points: Native (https://www.native.org/) is a cross-platform mobile framework that uses Type as the core language. Its user interface is built with XML and CSS.

When developers migrate business logic from a web application and use the same operating skills on its UI, the tool allows iOS and Android platforms to share approximately 90% of the code.

The idea behind Native is to write a single UI for mobile devices and fine-tune each platform according to specific needs.

Different from the hybrid cross-platform solution that uses WebView to render, the framework runs various applications in the Java virtual machine and directly connects to the native mobile API, thus ensuring high performance comparable to native applications .

React Native (https://facebook.github.io/react-native/): This Java framework is prepared for the cross-platform implementation of mobile applications and can support porting from the Web.

Compared with Native, React Native takes a slightly different approach: It encourages its community to write separate UIs for different platforms and adheres to the “learn once, write everywhere” approach.

Therefore, the degree of code sharing is 70%. In addition, React Native also has native API rendering capabilities similar to Native.

However, it needs to build an additional bridge API layer and use native controllers to connect to Java runtime.

In general, if you need to use the same business logic to run web and mobile applications at the same time, then these two frameworks are good choices.

Of course, Native is more focused on code sharing and shortening the product launch time; while React Native will use a longer development cycle in exchange for a closer native look and feel.

⑦Documentation and vendor support: insufficient documentation, relying on large communities

Since January 2018, as Google continues to develop the Angular ecosystem, they can not only provide long-term support (Long-Term Support, LTS) for the framework, but also focus on fixing bugs and positive improvements.

However, compared with the development speed of its framework, the corresponding document updates are not so timely. Some developers have expressed concern about the speed of updates to their CLI documentation.

The figure below is an interactive service interface (https://update.angular.io/) designed to facilitate the use of Angular developers. You can customize the current version and update target of the framework to get a list of updates.

Image for post
Image for post

Since AngularJS’s documentation (https://docs.angularjs.org/api) and tutorials provide a wider range than Angular 2+, it has been praised by developers.

The React community encountered documentation issues similar to Angular. Because the React environment and how it works are frequently updated, you must be prepared for changes and continuous learning when using React.

Although React already has some recent versions of the documentation (see: https://reactjs.org/versions/), keeping up with all the changes and integrations is not a simple task.

Fortunately, the support of its community has offset such problems to some extent. React has a large number of developers who can often share their knowledge on thematic forums.

⑧Learning curve: Angular is steeper

Angular’s learning curve is considered steeper than React. Angular is a complex and lengthy framework that can solve some single problems through various methods. However, it requires many repetitive operations to achieve complex component management.

As we mentioned above, the framework is constantly evolving, so developers have to adapt to various changes.

In addition, because Angular 2+ uses Type and RxJS, although Type is close to Java, users still need to spend some time learning RxJS.

Due to frequent updates, React also requires users to continuously learn. Of course, if you are already good at using Java, you don’t need to spend too much time starting over.

At present, because about 60% of React application construction will use Redux, Redux has become an essential tool, and the React learning curve is mainly determined by the Redux library.

However, React also provides a variety of practical tutorials for beginners, please refer to:

https: //reactjs.org/tutorial/tutorial.html

⑨Community and acceptance: the two are on par

React is slightly more popular on GitHub than Angular. It has 113,719 stars and 6,467 followers; Angular has only 41,978 stars and 3,267 followers.

According to the 2018 version of the Stack Overflow Developer Survey (as shown in the figure below), Angular’s developers accounted for 37.6%, while React’s users accounted for 28.3%.

It is worth mentioning that the survey covers AngularJS and Angular 2+ users.

Image for post
Image for post

Interestingly: Angular also leads in negative reviews. According to the same survey, 45.6% of developers think Angular is one of the worst frameworks.

Of course, such negative feedback may be affected by the fact that many developers are still using AngularJS. After all, AngularJS has more problems than Angular 2+. And Angular’s community is even larger.

Relatively speaking, React’s numbers are more attractive, with only 30.6% of professional developers unwilling to use it.

Which framework would you choose?

In summary, the basic idea behind Angular is to provide powerful support and toolsets for the overall experience of front-end development.

Thanks to the constant updates and active support of the Google team, the framework will not appear “savage growth”.

The engineers behind it will work hard to protect the existing community and assist various developers and companies to switch from AngularJS to Angular 2+ with higher performance and smaller application size.

At the same time, as your application gradually reaches an enterprise-level scale, Type can increase the maintainability of application code, so it becomes more and more important. Of course, these will also make developers face a steep learning curve.

React provides a more lightweight solution, suitable for developers who don’t have much learning time and need to get started quickly.

Although its code base does not specify various tool sets and methods, common tools such as Redux still require you to spend extra time to learn.

Moreover, because React’s performance is comparable to Angular, it is still very attractive to developers.

Written by

Digital Nomad

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store