Vue Versus React:IntroductionIn the past few years, JavaScript has been breaking ground in the tech industry with a wave of new client-side frameworks i.e. VueJS, React, Angular, Ember. The purpose of this document is to argue why the adoption of VueJS is more favorable than React.  Before diving in comparisons between VueJS and React, it is important to have a brief overview of these two frameworks.Overview of FrameworksReact OverviewReact is a Javascript library developed by Facebook which is utilized for constructing UI components which are reusable.

React focuses on the construction of reusable UI components which present data that is modified over a period of time. One of React’s selling points, is its ability solve the DOM (Document Object) problem. The DOM was never optimized for developing UI that are dynamic. The DOM could be worked on with using JavaScript and libraries like JQuery, however this did not solve the issue of performance. React abstracts away the DOM creating the Virtual DOM (A lightweight copy of the real DOM). Hence, rather than working on the real DOM, changes can be made on Virtual DOM and saved to the real DOM tree. Upon saving, the differences are found between the virtual DOM and the real DOM and then the Real DOM is re-rendered to match the virtual DOM.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!

order now

This process is much faster as it does not need all the heavyweight parts that utilized when working directly with the real DOM.Vue OverviewAccording to github, VueJS is a progressive, incrementally-adoptable JavaScript Framework for building UI on the web. VueJS influenced by many frameworks, adapting and improving their features from the following Frameworks:·         Reactive or computed properties from Knockout and Ember.·         One-way data flow and virtual DOM (Document Object Model) from React·         HTML style template that are directive heavy from Angular The topic of “Vue vs React” is very subjective among developers hence biases are determined can by the following:Templates — JSX or HTMLReat JSXWith React, all syntax is written in JavaScript. The approach is to have all CSS code in JavaScript and all HTML syntax expressed through JSX.  Hence, the UI of every component is expressed within render functions via JSX. This results in the following advantages:·         You can take full advantage of JavaScript to construct your view. Have the power to utilize flow controls, temporary variables and reference JavaScript values which are in scope·         JSX have a lot of support of tooling which is in some areas more progressive than Vue’s tooling support for templates.

E.g. Type checking, linting and editor autocompletionVue TemplatingThe nice thing about Vue is the fact the it also has render funtions and provides support for JSX due to the fact the under certain situation you will require the power of JSX. Vue provides templates by default as less complicated option. Any HTML structure is accepted and results in a few advantages:·         Preprocessors like Pug can be utilised·         Most inexperienced developers will feel a lot more familiar with working with HTML, hence the template feels easier to read and write.

·          There is less of a learning curve which results in designers and inexperienced developers being able to add to the codebase·         The process of migration for existing web applications to take advantage of Vue’s reactivity is a lot simpler due to Vue having HTML based templates.Achieving more with directivesAn argument could be made saying the one must know a Domain Specific Language (DSL) to construct template, however, I can personally say that DSL is easy to understand. Vue takes the directive style syntax from Angular and can help developers get a lot done with a reduced amount of code. One example would be the use of modifiers link v-on. More code would be required to perform the same task   Performance Render/Update PerformanceVue and React both have remarkably speed, both being very close speed is would not be a deciding factor under this category. For details view the link following link, which examines update/render performance with basic component trees. Hence In terms of performance for these two frameworks, let us turn our attention to performance optimization Performance OptimizationReact Optimization:When the state of a component is changed in React, this condition makes the entire component sub-tree re-render at the root of the component. Re-renders of child components that are not necessary can be sidestepped with the utilization of shouldComponentUpdate and Pure Component.

  To put it in simple terms shouldComponentUpdate and Pure Component are essentially used to make sure that when you get new data in some way, that it’s worth updating your tree. It is possible to utilize structures of data that are unchanging over time to ensure that modifications of your state are optimized. shouldComponentUpdate and Pure Component make the assumption that the render of the sub-tree is determined by the present component’s props. However, should this not be the case, then optimizations could result inconsistent stateVue Optimization:With VueJS’s reactivity model, all data (props, state etc.

) are observable by default, hence the system is aware of which components need re-rendering during a state change. So, in other words, every component has shouldComponentUpdate applied by default. Therefore, this removes the requirement for performance optimization classes, minimizing the developer’s work load, allowing him/her to spend more time on developing the web application as it grows.

Lifecycles and the Reactivity ModelThe reactivity model and lifecycles play a big role in performance optimization efforts. VueJS and React have extremely similar lifecycles. The following table shows the life-cycles of Vue and its equivalents in React Vue Lifecycles React Lifecycles beforeMount() {} componentWillMount() mounted() componentDidMount() beforeDestroy() {} componentWillUnMount() destroyed() componentWillUpdate render() componentDidUpdate()  The notable life cycles in React which do not have equivalents in VueJS are the following:·         componentWillReceiveProps()·         shouldComponentUpdate()·         componentWillUpdate()·         componentDidUpdate()These lifecycle hooks practically ensure that used to make sure that when you get new data in some way, that it’s worth updating your tree as mentioned before.

One would think that since Vue doesn’t have these missing lifecycle hooks that you can’t write high performance Vue, however, the secret lies within Vue’s reactivity model as mentioned briefly before. Let us take a look at some example comparing Vue’s reactivity to React’s reactivity to get a more detailed understanding:VueJS Reactivity Model Figure 1: Code snippet portraying Vue Reactivity·         Vue’s reactivity model is very similar to Ember.js.

All Vue data(props, state) are observable by default·         Vue automatically tracks reactive dependencies of functions. ·         Hence, in Figure 1, firstName is just being rendered. Figure 1 has more data that it could render i.e lastName, but since Vue is tracking the render call, when it rendered the first time, Vue takes note that it only uses firstName so down the line, if lastName gets updated, Vue will not even bother asking about re-rendering again since it know that its impossible for render to be using lastName. Hence the above render() will one be called when firstName is updated.

 Figure 2:  Code snippet portraying React ReactivityDuring a state change, you can intercept updates to your states and props and make a judgement call on whether or not, you can re-render. The issue is as your render function grows, you have to grow shoudlComponentUpdate() as well to keep it at high performance. ScalingScaling UpFor web applications on a big scale, both VueJS and React provide strong solutions. For state management, the community of React developed Scaling DownNative Rendering


I'm Erica!

Would you like to get a custom essay? How about receiving a customized one?

Check it out