Anuj Bansal, August 17, 2020
React vs Angular
React vs Angular: An In-depth Comparison

Where to Start?
Before you pick any tool, you need to answer two simple questions: “Is this a good tool per se?” and “Will it work well for my use case?” Neither of them mean anything on their own, so you always need to keep both of them in mind. All right, the questions might not be that simple, so we’ll try to break them down into smaller ones.
Questions on the tool itself:
- How mature is it and who’s behind it?
- What kind of features does it have?
- What architecture, development paradigms, and patterns does it employ?
- What is the ecosystem around it?
Questions for self-reflection:
- Will I and my colleagues be able to learn this tool with ease?
- Does it fit well with my project?
- What is the developer experience like?
Using this set of questions you can start your assessment of any tool and we’ll base our comparison of React and Angular on them as well.
There’s another thing we need to take into account. Strictly speaking, it’s not exactly fair to compare Angular to React, since Angular is a full-blown, feature-rich framework, while React just a UI component library. To even the odds, we’ll talk about React in conjunction with some of the libraries often used with it.
Maturity
An important part of being a skilled developer is being able to keep the balance between established, time-proven approaches and evaluating new bleeding-edge tech. As a general rule, you should be careful when adopting tools that haven’t yet matured due to certain risks:
- The tool may be buggy and unstable.
- It might be unexpectedly abandoned by the vendor.
- There might not be a large knowledge base or community available in case you need help.
Both React and Angular come from good families, so it seems that we can be confident in this regard.
React
React is developed and maintained by Facebook and used in their own products, including Instagram and WhatsApp. It has been around for around five years now, so it’s not exactly new. It’s also one of the most popular projects on GitHub, with about 119,000 stars at the time of writing. Sounds good to me.
Angular
Angular has been around less then React, but it’s not a new kid on the block. It’s maintained by Google and, as mentioned by Igor Minar, used in more than 600 hundred applications in Google such as Firebase Console, Google Analytics, Google Express, Google Cloud Platform and more.
Features
Like I mentioned earlier, Angular has more features out of the box than React. This can be both a good and a bad thing, depending on how you look at it.
Both frameworks share some key features in common: components, data binding, and platform-agnostic rendering.
Angular
Angular provides a lot of the features required for a modern web application out of the box. Some of the standard features are:
- Dependency injection
- Templates, based on an extended version of HTML
- Routing, provided by
@angular/router
- Ajax requests using
@angular/common/http
@angular/forms
for building forms- Component CSS encapsulation
- XSS protection
- Utilities for unit-testing components.
Some of these features are built-in into the core of the framework and you don’t have an option not to use them. This requires developers to be familiar with features such as dependency injection to build even a small Angular application. Other features such as the HTTP client or forms are completely optional and can be added on an as-needed basis.
React
With React, you’re starting off with a more minimalistic approach. If we’re looking at just React, here’s what we have:
- No dependency injection
- Instead of classic templates, it has JSX, an XML-like language built on top of JavaScript
- State management using
setState
and the Context API. - XSS protection
- Utilities for unit-testing components.
Not much. And this can be a good thing. It means that you have the freedom to choose whatever additional libraries to add based on your needs. The bad thing is that you actually have to make those choices yourself. Some of the popular libraries that are often used together with React are:
- React-router for routing
- Fetch (or axios) for HTTP requests
- A wide variety of techniques for CSS encapsulation
- Enzyme for additional unit-testing utilities.
We’ve found the freedom of choosing your own libraries liberating. This gives us the ability to tailor our stack to particular requirements of each project, and we didn’t find the cost of learning new libraries that high.
Languages, Paradigms, and Patterns
Taking a step back from the features of each framework, let’s see what kind higher-level concepts are popular with both frameworks.
React
There are several important things that come to mind when thinking about React: JSX, functional components, state management, PropTypes, and Flow.
JSX
JSX is a controversial topic for many developers: some enjoy it, and others think that it’s a huge step back. Instead of following a classical approach of separating markup and logic, React decided to combine them within components using an XML-like language that allows you to write markup directly in your JavaScript code.
While the merits of mixing markup with JavaScript might be debatable, it has an indisputable benefit: static analysis. If you make an error in your JSX markup, the compiler will emit an error instead of continuing in silence. This helps by instantly catching typos and other silly errors.
Functional Components
In React you can define components using functions and classes. Functional components are usually pure and provide a clear mapping between in the input props and the rendered output. Functional code is usually less coupled and easier to reuse and test. However, functional components in React have their limitations. For example, they cannot have a state as opposed to the class components. This requires the developers to switch between the two paradigms to make the best of both worlds.
The situation will change when the hooks proposal is finalized and released. This will allow functional components to have a state and use other features of class components, such as lifecycle hooks. We will then be able to write purely functional React applications.
State Management
The concept of state management is important for both frameworks and React has several approaches to offer. Each component can have its own state, so you can use that to create stateful components for holding the state of a part of the application. This is known as the lifting state up pattern. This, however, gets impractical as you need to store global state required in different parts of the application as well as manually pass data around different levels of the component tree. To mitigate this, React 16.3 introduced the Context API that allows you to make data available an all component tree levels without passing it around explicitly. Contexts don’t store the state themselves, they only expose the data, but if you wrap it in a stateful component you can implement a convenient natively supported way to store the state.
There are also third-party libraries for state management in React. Redux is a state management library inspired by Flux, but with some simplifications. The key idea of Redux is that the whole state of the application is represented by a single object, which is mutated by functions called reducers. Reducers themselves are pure functions and are implemented separately from the components. This enables better separation of concerns and testability.
MobX is an alternative library for managing the state of an application. Instead of keeping the state in a single immutable store, as Redux does, it encourages you to store only the minimal required state and derive the rest from it. It provides a set of decorators to define observables and observers and introduce reactive logic to your state.
- Further reading: How to Manage Your JavaScript Application State with MobX
PropTypes
PropTypes is an optional feature of React that can bring additional safety measures if you’re not using Flow or TypeScript. It allows you to define a set of validators for the props of components that will check their values at runtime. Since React 15.5 prop types have been moved to a separate prop-types library and are now completely optional. Considering its benefits, we advise to use it to improve the reliability of your application.
Flow
Flow is a type-checking tool for JavaScript also developed by Facebook. It can parse code and check for common type errors such as implicit casting or null dereferencing.
Unlike TypeScript, which has a similar purpose, it does not require you to migrate to a new language and annotate your code for type checking to work. In Flow, type annotations are optional and can be used to provide additional hints to the analyzer. This makes Flow a good option if you would like to use static code analysis, but would like to avoid having to rewrite your existing code.
- Further reading: Writing Better JavaScript with Flow
All three features can greatly improve your developer experience: JSX, Flow, and PropTypes allow you to quickly spot places with potential errors, and carefully choosing your aproach to state management will help achieve a clearer structure for your project.
Angular
Angular has a few interesting things up its sleeve as well, namely TypeScript, RxJS, and Angular Elements, as well as its own approach to state management.
TypeScript
TypeScript is a new language built on top of JavaScript and developed by Microsoft. It’s a superset of JavaScript ES2015 and includes features from newer versions of the language. You can use it instead of Babel to write state of the art JavaScript. It also features an extremely powerful typing system that can statically analyze your code by using a combination of annotations and type inference.
There’s also a more subtle benefit. TypeScript has been heavily influenced by Java and .NET, so if your developers have a background in one of these languages, they are likely to find TypeScript easier to learn than plain JavaScript (notice how we switched from the tool to your personal environment). Although Angular has been the first major framework to actively adopt TypeScript, it’s also possible to use it together with React.
- Further reading: An Introduction to TypeScript: Static Typing for the Web
RxJS
RxJS is a reactive programming library that allows for more flexible handling of asynchronous operations and events. It’s a combination of the Observer and Iterator patterns blended together with functional programming. RxJS allows you to treat anything as a continuous stream of values and perform various operations on it such as mapping, filtering, splitting or merging.
The library has been adopted by Angular in their HTTP module as well for some internal use. When you perform an HTTP request, it returns an Observable instead of the usual Promise. This approach opens the door for interesting possibilities, such as the ability to cancel a request, retry it multiple times or work with continuous data steams, such as web sockets. But this is just the surface. To master RxJS, you’ll need to know your way around different types of Observables, Subjects, as well as around a hundred methods and operators.
- Further reading: Introduction to Functional Reactive Programming with RxJS
State Management
Similar to React, Angular components can store data in their properties and pass them to their children. If you need to access values in sibling components you can move it to a stateful service that can later be injected into the components. Since reactive programming and RxJS is a first-class citizen in Angular, you can make use of observables to recalculate parts of the state based on some input. This, however, can get tricky in larger applications since changing some variable can trigger a multi-directional cascade of updates that is difficult to follow.
NgRx, the most popular state management library for Angular can make things easier. It’s inspired by Redux but also makes use of RxJS to watch and recalculate data in the state. Using NgRx can help you enforce an understandable unidirectional data flow as well as reduce coupling in your code.
NGXS is another state management library inspired by Redux. In contrast to NgRx, NGXS strives to reduce boilerplate code by using modern TypeScript features and improve the learning curve and overall development experience.
- Further reading: Managing State in Angular Apps with ngrx/store
Angular Elements
Angular elements provide a way to package Angular components as custom elements. Also known as web components, custom elements are a framework-agnostic standardised way to create custom HTML elements that is controlled by your JavaScript code. Once you define such an element and add it to the browser registry, it will automatically be rendered everywhere it’s used in the HTML. Angular elements provide an API that creates the necessary wrapper to implement the custom component API and make it work with Angular’s change detection mechanism. This mechanism can be used to embed other components or whole Angular applications into your host application, potentially written in a different framework with a different development cycle.
We’ve found TypeScript to be a great tool for improving the maintainability of our projects, especially those with a large code base or complex domain/business logic. Code written in TypeScript is more descriptive and easier to follow. RxJS introduces new ways of managing data flow in your project but does require you to have a good grasp of the subject. Otherwise, it can bring unwanted complexity to your project. Angular elements have the potential for re-using Angular components and it’s interesting to see how this plays out in the future.
Ecosystem
The great thing about open source frameworks is the number of tools created around them. Sometimes, these tools are even more helpful than the framework itself. Let’s have a look at some of the most popular tools and libraries associated with each framework.
Angular
Angular CLI
A popular trend with modern frameworks is having a CLI tool that helps you bootstrap your project without having to configure the build yourself. Angular has Angular CLI for that. It allows you to generate and run a project with just a couple of commands. All of the scripts responsible for building the application, starting a development server and running tests are hidden away from you in node_modules
. You can also use it to generate new code during development and install dependencies.
Angular introduces an interesting new way of managing dependencies to your project. When using ng add
you can install a dependency and it will automatically be configured for usage. For example, when you run ng add @angular/material
, Angular CLI downloads Angular Material from the npm registry and runs its install script that automatically configures your application to use Angular Material. This is done using using Angular schematics. Schematics are a workflow tool that allows the libraries make changes to your code base. This means that the library authors can provide automatic ways of resolving backward-incompattible issues you might face when installing a new version.
- Further reading: The Ultimate Angular CLI Reference
Ionic Framework
Ionic is a popular framework for developing hybrid mobile applications. It provides a Cordova container that is nicely integrated with Angular and a pretty material component library. Using it, you can easily set up and build a mobile application. If you prefer a hybrid app over a native one, this is a good choice.
Angular Material
If you’re a fan of material design, you’ll be happy to hear that there’s a Material component library available for Angular with a good selection of ready-made components.
Angular universal
Angular universal is a project that bundles different tools to enable server-side rendering for Angular applications. It is integrated with Angular CLI and supports a number of Node.js frameworks, such as express and hapi, as well as with .NET core.
Augury
Augury is a browser extension for Chrome and Firefox that helps to debug Angular applications running in development mode. You can use it to explore your component tree, monitor change detection and optimize performance issues.
There are plenty of other libraries and tools available in the Awesome Angular list.
React
Create React App
Create React App is a CLI utility for React to quickly set up new projects. Similar to Angular CLI it allows you to generate a new project, run the app in development mode or create a production bundle. It uses Jest for unit testing, supports application profiling using environment variables, backend proxies for local development, Flow and TypeScript, Sass, PostCSS, and a number other features.
React Native
React Native is a platform developed by Facebook for creating native mobile applications using React. Unlike Ionic, which produces a hybrid application, React Native produces a truly native UI. It provides a set of standard React components which are bound to their native counterparts. It also allows you to create your own components and bind them to native code written in Objective-C, Java or Swift.
Material UI
There’s a material design component library available for React as well. Compared to Angular’s version, this one is more mature and has a wider range of components available.
Next.js
Next.js is a framework for the server-side rendering of React applications. It provides a flexible way to completely or partially render your application on the server, return the result to the client and continue in the browser. It tries to make the complex task of creating universal applications easier so the set up is designed to be as simple as possible with a minimal amount of new primitives and requirements for the structure of your project.
There are plenty of other libraries and tools available in the Awesome React list.
Gatsby
Gatsby is a static website generator that uses React.js. It allows you to use GraphQL to query the data for your websites defined in markdown, YAML, JSON, external API’s as well as popular content management systems.
React 360
React 360 is a library for creating virtual reality applications for the browsers. It provides a declarative React API that is built on top the WebGL and WebVR browser APIs thus making it easier to create 360 VR experiences.
React Developer Tools
React Dev Tools is a browser extension for debugging React applications that allows you to traverse the React component tree and see their props and state.
Development Mode
- Anuj Bansal 077Friday, November 6, 2020 9:58 AM
asasasLikes 0 - Anuj Bansal 077Tuesday, November 3, 2020 10:41 AM
heeelllloooLikes 0