React and React Native are Facebook brainchildren that differ in the focus area. One is meant for web app development and another allows you to build cross-platform mobile applications. At the same time, they have much in common to be introduced in this blog post.
React Native vs. React = little vs. elder brother
Before we can delve into differences and peculiarities of both technologies, let’s take a look at the major similar thing they share – the idea. React and React Native were created to simplify and accelerate the creation of web and mobile user interfaces using a powerful programming language – JavaScript. And it worked out. Over more than five years of existence, React acquired the title of the most growing-in-popularity JS library in 2017 and plans to run for it in 2018 as well. React Native has several battle-fronts, and it boldly fights against not only hybrid app technologies but also native ones.
Of course, these technologies are not competitors or rivals to each other. They are more like brothers or sisters if you wish. In this article, we’re not explaining the problem of choice between them, but what you obtain when using them in web and mobile app building.
What is React js?
The principal thing to be mentioned about React is that it’s a library rather than a framework. Its major aim is to create UI in web apps with regularly changeable data. You may also encounter another popular definition of this JS library – the view layer out of the MVC (model-view-controller) architecture pattern. Well, React is not a view replacement but a sort of dopant. Unlike traditional web app’s UI based on templates, Facebook’s library uses components to make the view more modular. It means, each component is a structural element of the user interface. Besides, components are reusable which allows you to build a custom UI library for your product or organization.
Traditionally, React is mostly leveraged for creating single-page applications. However, this is not to say that it is not suitable for building multi-page apps. The Facebook app is proof of that. In case you’re wondering who is using React aside from its creator, take a look at the UIs of Netflix, WhatsApp, and Dropbox. The list is huge. So, what’s so special about this JS library?
React key features
This is a brief introduction to key features you’ll find in the library.
- Virtual DOM
Document Object Model (DOM) is a UI representation handled by the browser. Most JavaScript libraries (e.g., jQuery) use it directly to manipulate the UI. With React, you can leverage Virtual DOM, which is an in-memory structure that is kept in sync with “real” DOM through a highly efficient reconciliation algorithm. It minimizes the amount of operations to be performed on “real” DOM to increase performance. Updates are very quick that makes your UI incredibly responsive.
NB: Virtual DOM by itself would do little to help. However, if it is combined with a highly efficient reconciliation algorithm based on smart heuristics, you get a powerful combination that people usually refer to as a Virtual DOM.
- Unidirectional data flow
As you can understand from the name, data goes through the app in one direction from parent components to their children. As a result, the view does not have to be updated all the time the state changes. It remains the same and re-renders itself to reflect only the relevant state changes.
- JSX
This is a syntax sugar to describe the UI’s appearance. JSX is a sort of mixture of HTML and JS. Some developers love its versatility and usefulness; others complain about its complexity. Nevertheless, it’s a distinctive feature which can be deemed either a barrier or one of React JS’ advantages.
Here is how the phrase “Who is John Galt?” would look like in JSX:
const person = { firstName: 'John', lastName: 'Galt', }; const fullName = person => ( [person.firstName, person.lastName].join(‘ ‘) ); const component = {`Who is ${fullName(person)}?`}; ReactDOM.render(component, document.getElementById('root'));
Now, let’s close the hood and move from React JS features to its advantages and drawbacks.
React pros
- Learning
The library is very simple to learn. It has a rather simple syntax that is within the grasp of any HTML-savvy engineer.
- Performance
Faster programming and high performance are achievable due to the abovementioned virtual DOM. Another benefit provided by this React app structure is a responsive UX. As a result, both developers and users are satisfied.
- Efficiency
Code reusability is an additional developer efficiency booster. React allows engineers to reuse code components. Designers, in turn, can reuse the same design assets. The flexible coupling of components means that changing one won’t affect others.
- Debugging
The error handling process is simple and convenient because:
- React components are simple and work in a way that is easy to predict
- unidirectional data flow
- there are great tools for React like React Developer Tools.
Despite some opinions that search ranking can be hurt if we use React for app building, the library is capable of providing seamless SEO integration. This is possible due to fast page load and the server-side rendering.
- JavaScript
This programming language underlies the library, which means you get access to a vivid society of contributors and enthusiasts across the globe.
- Toolset
React provides engineers with a bunch of tools for efficient and convenient work. These include React Developer Tools (inspection of the hierarchies of components in the vDOM), React Sight (visualization of component hierarchy tree), Reselect (selector library), and many others to make an engineer’s life easier.
React cons
The list of React JS disadvantages is short and mostly based on the most widespread complaints about the library.
- Unopinionated nature
React is over-dependent on a plethora of versatile tooling and external libraries. Having too much to choose from may be serious hassle for developers.
- JSX
It’s not an undisputed drawback since some engineers find this syntax sugar rather practical. However, you’ll have to spend some time to master it and get used to its similarities and differences from HTML.
- Documentation
Inadequate Facebook React documentation is discovered when you compare it with other JS libraries or frameworks like Vue.js or Angular. However, it’s an ad hoc issue.
Why React is a choice?
Today, Facebook’s technology enjoys huge rates of growing popularity among other JS libraries. Another proof of its progress is a rising market demand for React engineers. There are many reasons to use React for building a web app including the virtual representation of HTML in memory, reusable and composable components, reactive updates of the state changes, etc. From the business perspective, you obtain a useful and substantial solution prepacked with various auxiliary tools.
As you can see from the chart below, the search interest in React has been growing since the very outset. Moreover, in 2016, the library overcame Angular in popularity and became one of the most sought front-end technologies. In the blog post titled Battle For the Front-End, we compared different facets of React vs. Angular.
In addition to the library’s benefits and hallmarks, React for mobile is also possible. Do you want to know how? The answer lies with its younger brother described below.
What is React Native?
Unlike the elder brother, React Native is a framework. It implements most of React’s working principles for building close-to-native mobile applications. React Native is a combination of two app development approaches – native and JS-based. Most of the code is written in JavaScript, while some computationally heavy platform-specific features are done with native plugins.
It works as follows:
- WebKit runs JavaScript logic that produces virtual DOM
- virtual DOM is reconciled on the JS side
- JS sends instructions on how to change the native view hierarchy through JS-to-native bridge
- native view hierarchy is updated
The main point here is that view hierarchy is rendered using native components. It’s not the case of hybrid apps when WebView is involved where WebView is rendered natively, and the content within WebView is rendered as a plain old website. Ionic is a typical example of the hybrid development framework. Check out the key differences and similarities between React Native and Ionic.
Therefore, React Native apps provide the real native UX in most cases. And developers are not necessary to be experts in Java/Kotlin/Objective-C/Swift unless there is an aim to max out the framework’s potential and mix JS with the native code. Earlier, we blogged about React Native vs. native app development.
One app for all platforms?
It’s most likely that cross-platform app development is the reason why React Native is known. The framework is rather young but already stands out of traditional approaches to mobile app building. Its major trump card is code reusability. Developers appreciate that because it allows them to save time and hence money. Judge for yourself – there is no necessity to create separate software products for different operating systems. You focus on the bulk of the reusable JS code which can reach up to 95% (Walmart app example) and enhance it with native modules or code as well. One development team instead of two or more for companies that opt for native app development approach. Checkmate.
However, it’s not the only benefit you get with the framework. Let’s have a look at other React Native pros and cons.
React Native pros
- Code reusability. Nothing to add more.
- High performance
React Native apps are not native at their core, but they are close to them in terms of performance. The bridge connecting the app’s logic and native elements slows down the performance a bit.
- Responsive UI
Native components not only improve the performance but also enhance the user experience. There is no unified set of components – all of them are platform-specific.
- React at heart
The elder brother gave most of its benefits to the younger one. I.e., JavaScript plus React’s syntax are obligatory to get in the mobile app technology. However, to master it in full, you’ll have to learn platform-specific APIs, design patterns, language basics, and probably read one of these books.
- React Native UI components
If you need to customize your app, you can either deepen your knowledge of architecting native elements by yourself or take advantage of versatile ready-to-use UI components available in the React Native community. Here you can see our picks.
- Hot & live reloading
This feature of the React Native framework lets you tweak the user interface without any loss of your app’s state. You can use live instead of hot reloading if the business logic needs to be modified.
- Declarative UI
Mobile UI with React Native is based on a declarative programming paradigm. It means an engineer focuses on what is needed to be implemented rather than how to do this. This approach is debugging-friendly and excludes the necessity of building a sequence of actions within the app.
React Native cons
- Native API
Most native APIs are supported by the framework. However, some of them require additional native modules.
- Native modules
These cover different native features and functionalities like access to sensors, push messages, camera, battery info, etc. Unfortunately, JS is not enough to implement them, and developers need expertise in platform-specific language.
- React at heart – reverse side of the coin
The JS library as a core of the React mobile framework can be a drawback as well. If you’re not familiar with the elder brother’s fundamentals like JSX, writing approach, and so on, you’ll have to spend time on learning both Facebook’s technologies from the ground up.
- Design
Placement of the graphical elements with React Native is carried out automatically for each OS. Sometimes it is not a fit, and the app suffers from placement issues. Be prepared to struggle with this sort of React Native limitations to clean up the design.
Why React Native is a choice?
We won’t ramble on the viability of React Native app development. It is an awesome technology chosen by Instagram, Skype and many other mobile apps. They’ve opted for the framework for different reasons but all they have a similar origin – high development efficiency.
With the advent of React Native in 2015, cross-platform development was mostly ruled by hybrid frameworks – Ionic and PhoneGap. However, Facebook’s pet project managed to overcome both tools in search interest within almost two years. Today, it is an undisputed leader in this niche.
React Native lets you significantly cut your product’s time to market. Your team won’t dissipate efforts on creating one app for iOS, one for Android, one Windows, etc. Thanks to code reusability, most of your JS code base can be shared between different platforms and save a bunch of time.
When we say time, we mean money as well. The framework is open source, and you do not need to abnormalize your budget to make a product that will satisfy both iPhoners and Androiders. So, if your aim is a decent alternative to native app development, it’s a challenge to find anything better than React Native. Also, you may check out our blog posts dedicated to debugging and adding a geolocation search feature with the framework.
Difference between React and React Native
In general, everything is clear. React is for web and React Native is for mobile. Moreover, the latter is built atop of the first one. However, let’s see in detail what is different and similar between the two brothers.
Name | React | React Native |
---|---|---|
Type | JS library | Framework |
Focus area | Web | Mobile |
Development model | Open-source | |
Syntax | ECMAScript 6, JSX | |
Set up | One command to set up:npx create-react-app my-app or npm init react-app my-app or npm init react-app my-app | Very fast; one command line to run the framework |
UI rendering | DOM | Platform-specific APIs |
Components styling | No CSS | |
Animations | CSS animations | |
Navigation | React Router | React Native tools |
Bonus: React 360 – another brother?
The history of the youngest brother in the React family began in 2017 with the name React VR. It was another JS library used for the creation of interactive UIs for not simple web apps but virtual reality ones. Later on, VR was rebranded into 360 due to some Facebook’s in-house circumstances.
React 360 inherited the working principles and advantages of the eldest brother. At the same time, it borrowed the main concepts (style, layout, state, etc.) from the React mobile framework.
What is it for?
With the growing virtual reality trend and the rise of versatile VR devices like Oculus Rift, Samsung Gear VR, Sony PlayStation VR, and others, the market of VR apps began to expand. However, the library is not focused entirely on VR devices and offers to enjoy 360 scenes using a regular portable device or web browser.
It is not meant to be leveraged for developing VR games. The niche of React 360 is 3D images and interactive UIs to deliver a never-to-be-forgotten UX.
Wrapping up
To end up our review of Reactjs vs React Native let’s sum up some takeaways from the above.
React | React Native |
---|---|
UIs for web apps | with a native feel principles of React UI components operating systems due to code reusability |
Facebook, Netflix, WhatsApp, Atlassian | Instagram, Classcraft, Skype, Tesla |
We haven’t found a winner when comparing React to React Native. And that was not the aim of our review. These are two awesome technologies with different intended uses. Each of them has blossomed in its focus area. React maintains the status of the JS library with the highest popularity growth rate. React Native, in turn, is often named the future of mobile app development. It’s up to you which one to choose. Anyway, now, you know the difference.