Angular vs. React vs. Vue (Part II: Essential Syntax and Features)

In this article, I’m comparing my learning experience with Angular (version 6.0.3), React (version 16.4.1), and Vue (version 2.5.16). I used mostly the official documentation for each framework.

In part I, I created a “Hello, world!” app with each framework. I used CLI only to create the Angular app; I created the React and Vue apps simply by referencing the JavaScript file(s) in the HTML file. For this article, I’ve created a “To Do” app with each framework and I used the CLI to set up the project for each.

"To Do" App

“To Do” App

The “To Do” app allows a user to enter a to-do item, and the item will be listed among other to-do items previously entered. Each to-do item in the list can be deleted by clicking the “Remove” button next to it.

In this app, I tried to cover the use of list, conditional rendering, form, event handling, and component.

Sample Code

Angular

React

Vue

Component (and Code Organization)

For this app, I came up with a component TodoList whose responsibility was, given a list of to-do items, to render a list of those items.

For the Angular app, I used the Angular CLI to create a new component. It generated four files (.css, .html, .spec.ts, and .ts) within a new folder. The CLI also automatically registered the new component with the app.

With the React app, I simply created a single file TodoList.js which contained the definition of TodoList component. This component was responsible for both logic and rendering the UI using JSX code.

Vue contained the template and logic in one single .vue file. Unlike React, though, the HTML and JavaScript code was in distinct, separate sections within the file.

One of interesting observations when creating this “To Do” app was the number of affected files.

# of Files Affected Files
Angular 5 app.module.ts, app.component.ts, app.component.html, todo-list.component.ts, todo-list.component.html
React 2 App.js, TodoList.js
Vue 2 App.vue, TodoList.vue

List

Angular and React use a common for-loop construct with only slight syntax difference. React utilized the method map() to generate the listing. Each method doesn’t seem to matter in practice, other than the construct using map() looks more verbose.

List template. (Left to right: Angular, React, Vue.)

List template. (Left to right: Angular, React, Vue.)

Conditional Rendering

Angular and Vue use an “if” directive within HTML code to determine which code will render the actual DOM. React allows using “if” construct to accomplish the same. React also offers inline if-else using a ternary operator.

Conditional rendering. (From left to right: Angular, React, Vue.)

Conditional rendering. (Left to right: Angular, React, Vue.)

Event Handling

In regard to event handling, Angular, React, and Vue share similar syntax on the template side. React needs an additional line of code to bind the event handler method, which feels tedious at times. React’s documentation provide a couple ways to get around this.

Event Handling Markup. (From left to right: Angular, React, Vue.)

Event Handling Markup. (left to right: Angular, React, Vue.)

Event Handling Code Behind. (From left to right: Angular, React, Vue.)

Event Handling Code Behind. (Left to right: Angular, React, Vue.)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.