What is the difference between React Native and React?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
React and React Native are both open-source libraries developed by Facebook that are widely used for building user interfaces. While they share a common architectural foundation and philosophy, they cater to different platforms and have distinct purposes and functionalities. Understanding their differences is key for developers choosing the right technology for their project.
Core Philosophy and Common Ground
React, also known as React.js, was introduced in 2013 and is a JavaScript library for building dynamic user interfaces for web applications. React Native, launched in 2015, extends React's architecture to build native mobile applications for iOS and Android.
Both use JSX (JavaScript XML), which allows developers to write HTML in React within JavaScript code. They share the same design principles, such as the virtual DOM (Document Object Model) for efficient re-rendering of the UI, and a component-based structure where each component maintains its own state and logic.
Platforms Targeted
The key difference between React and React Native lies in their target platforms:
- React is used for web development.
- React Native is used for mobile app development on platforms like iOS and Android.
Technical Interventions
Rendering Components
In React, components render to a web browser's DOM. Developers typically use additional libraries like ReactDOM for rendering workflows specific to web browsers.
React Native, however, does not use HTML to render components. Instead, it uses native components that map to real, native iOS or Android UI components that render directly to the mobile device’s screen.
Styling
React uses CSS for styling. This can be done using external style sheets or inline styling.
React Native has a different approach, using a JavaScript object to style components. The styling properties closely resemble CSS but use camelCase syntax like backgroundColor instead of background-color.
Navigation
In web applications built with React, browser-based routing is used. React Router is a popular library that helps manage transitions between different views in the application.
React Native uses libraries like React Navigation or react-native-router-flux, which provide a more mobile-centric method of navigation, such as tab navigation, stack navigation, or drawer navigation.
Development Environment and Setup
- React development typically involves setting up a code bundler like Webpack and a development server.
- React Native comes with its own CLI tool called
create-react-native-appwhich simplifies the process of setting up a new mobile app project.
React Native additionally requires developers to have either Xcode or Android Studio to run the iOS or Android simulations, respectively.
Performance
React applications run on the web, so their performance often depends on the browser's capability to render JavaScript quickly.
React Native applications, by comparison, have the advantage of leveraging the device's native performance capabilities which can be considerably faster, as it converts the JavaScript components into native platform-specific ones.
Use Cases
Choose React for:
- Rich interactive web applications.
- Projects where SEO might be a concern as server-side rendering is more SEO-friendly.
- Applications where progressive web app (PWA) features are needed.
Choose React Native for:
- Projects aimed at a native mobile experience without the complexity of learning Swift/Objective-C or Java/Kotlin.
- Applications that need to access mobile-specific functionalities like the camera, accelerometer, etc.
Summary Table
| Feature | React | React Native |
| Platform | Web | iOS and Android Mobile Apps |
| Component Rendering | Renders to DOM | Renders to Native Components |
| Styling | CSS | JavaScript Objects |
| Navigation | React Router | React Navigation, Native Navigation |
| Development Tools | Webpack, Babel | React Native CLI, Xcode, Android Studio |
| Performance | Depends on browser | Close to native performance |
| Typical Use Case | Web apps (SPA, MPA) | Native mobile apps |
By understanding these differences, developers can better decide which platform suits their needs for specific applications. As both are JavaScript-based and share similar design philosophies, transitioning between them or integrating them into a single project can be more straightforward than working with entirely different frameworks.
Related reading
- What is the difference between <section> and <div>?
- What is the difference between String.slice and String.substring?
- What is the difference between substr and substring?
- What is the difference between synchronous and asynchronous programming in node.js
- What is the difference between static func and class func in Swift?
- What is the difference between View.postDelayed and Handler.postDelayed on the main thread?
- What is the difference between visibility:hidden and display:none?
- What is the equivalent to a JavaScript setInterval/setTimeout in Android/Java?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.