Differences between Vue and React

There aren’t many differences between React and Vue. Two front-end frameworks are very similar – they both rely on Virtual DOM, they are based on components, and both are used to implement dynamic features.

In this article, we will try to summarize most important between React and Vue.

Background information – React and Vue

Vue was created by a former Facebook employee, who had the first-hand experience of writing applications in React. It was supposed to be an improved version of React, and in some ways, it is indeed better. For example, its syntax is more simple and approachable even for new developers.

JSX vs HTML

The most important difference is that Vue supports HTML, but React doesn’t. If you have a simple HTML page, you can easily include a CDN link for Vue and have dynamic features running in no time.

In React, we write a markup in JSX, a syntax that is similar to HTML. However, it’s just another way to write JavaScript in a familiar syntax. This approach has advantages as well as disadvantages. For example, it allows you to include JavaScript inside structure of the page. You can use this opportunity to define inline event handlers and get value from input fields in React.

If you’re coming from a background of traditional web development, you’ll find it easier to develop web applications in Vue.

Familiar Syntax

Traditional web development is done in CSS, HTML and JavaScript. React does everything in JavaScript, so there’s a little bit more learning curve involved.

Vue follows the traditional paradigm of writing front-end application in CSS, HTML and JavaScript. You can write markup in HTML, style web applications in CSS. More importantly, Vue provides a great foundation for implementing dynamic features in JavaScript.

Package size

This is not a crucial factor, because both React and Vue are relatively lightweight. But it’s still a fact that React is a bit more heavy than Vue. It might affect loading time for users with slow internet. Also, React needs other additional packages to function as a full framework, whereas Vue contains everything necessary in itself.

Easier to learn

Vue is easier to learn for multiple reasons. First of all, its syntax is already familiar to most front-end developers. Second, Vue has a great documentation, which explains everything you need to know about the framework. React’s documentation is good as well, but Vue’s documentation is slightly better.

Styling in CSS

Vue provides an easy way to style components. All you have to do is define an opening and closing <style> tags for each components. More importantly, you can avoid the cluttering of global namespace for classes by using the scoped keyword.

React has more JavaScript-cented approach to styling components. Libraries like ‘styled-components’ offer great features for dynamic styling. SimpleFrontEnd has a great post about conditional styling in React:

One disadvantage of React’s advanced approach is that it’s not always necessary. If you’re building a basic application with some dynamic features, React might be an overkill for that purpose.

Vue has a built-in system for applying dynamic classes. And it allows you to customize the appearance of your components using simple CSS rules and HTML. You don’t have to learn a new syntax or templating language like you do in React.

TypeScript vs JavaScript

Most recently, TypeScript has become an incredibly important tool for building web applications. It is especially important for building scale web applications, because TypeScript ‘tames’ wild nature of JavaScript. What I mean by this, is that by default, JavaScript can be quite unpredictable. Things like type coercion and other odd JavaScript behavior can be confusing. TypeScript solves all those problems and helps you maintain large codebase.

What is TypeScript?

It is an extension of JavaScript with extra features. Essentially, it is an improved version of JavaScript.

It has a slightly different syntax for writing JavaScript, but ultimately it is ‘translated’ to JavaScript once the code is executed.

It is commonly used for creating web applications because projects like Netflix and Disney plus are getting increasingly complex. There are many projects that contain thousands of lines of code. Maintaining all that would be impossible using default TypeScript.

TypeScript was first released in 2013 by Microsoft.

TypeScript vs JavaScript – which one is better?

First of all, it’s important to understand that TypeScript is not a different programming language. It’s the same as JavaScript. The biggest advantage of TypeScript is that it fixes the biggest and most confusing part of JavaScript – type coercion.

JavaScript has a confusing way of converting one data types into others. For example, adding a string to an integer will convert both values to strings. Let’s look at this example

5 (number) + ‘5’ (string) will be ‘55’ (string). It will not be 10.

Any time you decide to work on a large project, you definitely need TypeScript to find bugs and fix them. Fixing errors in JavaScript is very difficult. It’s hard to identify where the errors are, and even more difficult to fix them without messing up other parts of your code.

JavaScript is better in a sense that it gives you freedom and ability to improvise. TypeScript is much more fixed and errors are easy to fix.

TypeScript's consistency is especially useful when dealing with side effects. Here's a great resource about workings of useEffect library without a dependency array.

TypeScript with front-end frameworks

Because TypeScript is necessary for maintaining a large scale project, all three major JavaScript frameworks – React, Vue, and Angular support TypeScript.

Angular has always supported TypeScript, and it’s impossible to write Angular applications with normal JavaScript.

React and Vue are compatible with normal JavaScript, but the use of TypeScript is highly encouraged, especially in React, according to SimpleFrontEnd. For the past few years, most of commercial web application development in React is done with TypeScript.

Vue tries to stick with the traditional approach of writing web applications in HTML, CSS, and JavaScript. However, with the release of Vue 3, this front-end framework has also developed a solid support for TypeScript.

An important difference

Some people claim that JavaScript is an object-oriented language, but it’s not a clear conclusion. TypeScript, on the other hand, clearly follows an object-oriented pattern. Like its sister language JavaScript, TypeScript defines what you can and can not do through prototypes.