Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Key Points


References

Reference_description_with_linked_URLs_______________________Notes______________________________________________________________










https://programmingwithmosh.com/react/react-vs-angular/compare angular and react - p1
https://rubygarage.org/blog/react-vs-angularjscompare angular and react - p2





Key Concepts




Compare Angular and React

https://programmingwithmosh.com/react/react-vs-angular/

...

  • React-router for routing
  • Redux or MobX for state management
  • Enzyme for additional testing utilities

DOM vs Virtual DOM

React's virtual DOM has fast updates to the specific items in the DOM

Angular updates the full DOM until all the changed items have been updated - slower


Templates

React decided to combine UI templates and inline JavaScript logic, which no company had ever done before. The result is called “JSX”

...

Angular uses templates that are enhanced HTML with Angular directives (“ng-if” or “ng-for”). React only requires knowledge of JavaScript, but with Angular, you must learn its specific syntax.

Components

Both React and Angular are both component-based. A component receives an input, and after some internal logic returns a rendered UI template (a sign-in form or a table for example) as output. Components should be easy to reuse within other components or even in other projects

State management

The UI is described by the component at a given point in time. Then, the framework re-renders the entire UI of the component when data changes. This ensures that the data is always up to date.

To handle state in React, Redux is often used as the solution. In Angular, you may not need Redux. But, if your application becomes large enough, chances are that you will. Some developers, including me, opt to use MobX instead of Redux. MobX has more “magic” (things automatically done for you behind the scenes) and I personally prefer it.

Data Binding

A large difference between React and Angular is one-way vs. two-way binding. Angular uses two-way binding. For example, if you change the UI element (a user input) in Angular, then the corresponding model state changes as well. Additionally, if you change the model state, then the UI element changes – hence, two-way data binding.

...

to implement a unidirectional data flow in React, Facebook created its own application architecture called Flux. Flux controls the flow of data to React components through one control point – the dispatcher. Flux's dispatcher receives an object (they call it an action) and transfers it to an appropriate store, which then updates itself. Once the update is finished, the View changes accordingly and sends a new action to the dispatcher. It's only possible to transfer an action to the store when it’s fully updated. With this concept, Flux improves the effectiveness of the code base. Based on our own experience we can say that Flux is great when you work with dynamically updated data.


Typescript vs Javascript Flow

React uses JavaScript, a dynamically-typed language (which means you don’t have to define the variable’s type). Because many developers already know and love JavaScript, this can be seen as a pro. With ES6, you have modules, classes, spread operators, arrow functions, template literals and more. It allows developers to write declarative code while having the characteristics of a true OOP language (that is, including class-based structure).

...

// JavaScript (ES6)
function getName(name, age){
return name + age;
}

// TypeScript
function getName(name: string, age: number){ // <-- static typed!
return name + age;
}

================================
Classes in Javascript vs Typescript

// JavaScript (ES6)
class Greeter {
constructor(message) {
this.greeting = message;
}

greet() {
return "Hello, " + this.greeting;
}
}

let greeter = new Greeter("JavaScript!");
greeter.greet()

// Hello, JavaScript!

================================
// TypeScript
class Greeter { // <-- static typed!

greeting: string;

constructor(message: string) {
this.greeting = message;
}

greet() {
return "Hello, " + this.greeting;
}
}

let greeter = new Greeter("TypeScript!");
greeter.greet()

// Hello, TypeScript!


Mobile Apps

Angular and React both offer solutions to create mobile applications.

...

React Native, on the other hand, is a platform developed by Facebook for creating truly native mobile applications using React. The syntax is slightly different, but there are much more similarities than differences. Unlike Ionic, which is simply a glorified web app, React Native produces a truly native UI. It also allows you to create your own components and bind them to native code written in Objective-C, Java, or Swift.


Testing frameworks

Jest is used by Facebook to tests its React code. It is included in every React project and requires zero configuration to use. It also includes a powerful mocking library. Many times Jest is used in combination with Enzyme (a JavaScript testing utility used at Airbnb).

Jasmine is a testing framework that can be used in Angular. Eric Elliott says that Jasmine “results in millions of ways to write tests and assertions, needing to carefully read each one to understand what it’s doing”. The output, in my opinion, is also very bloated and difficult to read. Here are some educational articles on the integration of Angular with Karma and Mocha.


Dependency Management

Angular

Angular has built-in management

AngularJS uses a basic Object Oriented Programming (OOP) pattern called dependency injection, meaning we write dependencies in a separate file. It’s inconvenient to create a dependency directly in an object. In AngularJS, dependency injection is inherent to any standard functions that we declare for an AngularJS factory or service. We only pass dependencies as parameters in any order in our functions.

React

React needs 3rd party tool like renovate

The difference between React and AngularJS with regards to dependency injection is that React doesn’t offer any concept of a built-in container for dependency injection. But this doesn't mean we have to think of a method to inject dependencies in our React project. You can use several instruments to inject dependencies automatically in a React application. Such instruments include Browserify, RequireJS, EcmaScript 6 modules which we can use via Babel, ReactJS-di, and so on. The only challenge is to pick a tool to use.

Learning process

React

The first thing you’ll learn in React is JSX. It may seem awkward to write at first, but it doesn’t add much complexity. You’ll also need to learn how to write components, manage internal state, and use props for configuration. You don’t need to learn any new logical structures or loops since all of this is plain JavaScript.

...

It may seem like React has a lower barrier for entry, and I would most certainly have to agree. However, that doesn’t mean that React is “better”. I encourage you to try both React and Angular to see which one you personally prefer.


what frameworks are developers interested in? 2018


Summary

Angular:

  1. Is a full framework
  2. Has a Regular DOM, which renders updates slower than React’s Virtual DOM
  3. The rendered JavaScript and HTML maintains a physical separation
  4. Utilizes Components: emerging web components standard
  5. Data Binding: two-way
  6. You must use TypeScript
  7. Mobile: Ionic and Cordova are slower than React Native
  8. Testing:  Jasmine & Mocha
  9. Learning Curve is higher, but once you understand it you have an entire MVC framework
  10. Scalability: easy to scale
  11. Popularity: dropped since AngularJS (Angular 1)
  12. Open source: GitHub stars: 40,963 / Contributors: 732 / Issue: 2,162
  13. Size: larger, resulting in longer load times and performance on mobile
  14. Used on: Google, Nike, Forbes, Upwork, General Motors, HBO, Sony

...

  1. Just a small view library
  2. Has a Virtual DOM, which renders updates faster than Angular’s Regular DOM
  3. Uses JSX, which combines markup and logic in the same file (making components easier to read)
  4. Components: emerging web components standard
  5. Data Binding: one-way
  6. You Can use ES6/7 JavaScript, although you can use Typescript or Flow if you so choose
  7. Mobile: React Native is faster than Angular’s solutions
  8. Testing: Jest & Enzyme
  9. Learning Curve is lower, but you only get the view. Because of this, you’re going to have to learn a slew of 3rd party libraries. Ex. State management (Redux or MobX), Asynchronous calls (react-promise, react-thunk, or react-saga), etc.
  10. Scalability: is more testable, so also easy to scale
  11. Popularity: has increased exponentially
  12. Open source: GitHub stars: 111,927 / Contributors: 1,242 / Issues: 287
  13. Size: smaller than Angular, so a bit faster
  14. Used on: Facebook, Airbnb, Uber, Netflix, Instagram, Whatsapp, Dropbox
  15. React Fiber will increase the speed of React dramatically


Mosh's React Course

https://codewithmosh.com/p/mastering-react

$29 one time payment for course



Potential Value Opportunities



Potential Challenges



Candidate Solutions



Step-by-step guide for Example


Info


sample code block

Code Block
languagetext
titlesample code block
linenumberstrue
collapsetrue



Recommended Next Steps



Page Properties
hiddentrue


Related issues


...