What is the difference between react and react native
The difference between react and react native is: 1. The platform on which the framework works is different; 2. The working principle is different; 3. The rendering cycle is different; 4. All elements in react native will be replaced by the react components specified by the platform ;5. The APIs of the host platforms are different.
The environment of this article: windows10, react16 version, Dell G3 computer.
(Learning video sharing: react video tutorial)
The differences are as follows:
1. The platforms used by the framework are different
RN It is derived from React. Both frameworks use JSX development syntax, but RN is a JS framework used to develop truly natively rendered iOS and Andriod mobile applications, while React uses the browser as a rendering platform.
2. The difference in working principle
Virtual DOM is between the view described by the developer and the view actually rendered on the page. If you want to render an interactive user interface on a browser, developers must operate the browser's document object model. The emergence of Virtual DOM is to save the performance consumed by this part of the operation.
But the huge potential of Virtual DOM lies in this abstraction layer, which can bring many possibilities.
The working principle of React Native is to call the Objective-C API to render iOS components and the Java API to render Android components instead of rendering to the DOM. Bridging allows React to call UI components opened by the host platform, and the React component returns the markup code describing the interface through the render method. If it is a web platform, React will eventually parse the markup code into the browser's DOM; in React Native, the markup code will be parsed into platform-specific components, for example,
3. Rendering cycle
The rendering cycle of React starts after the react component is mounted to the DOM, and then React enters the rendering cycle and renders the component as needed. In the rendering phase, React renders the HTML tags returned by the developer in return directly to the page on demand.
The React Native life cycle is basically the same as React. In terms of rendering, because React Native relies on bridging and does not run on the UI main thread, it can execute these asynchronous calls without affecting the user experience.
4. Create components
When writing React for the web environment, the view ultimately needs to be rendered into an ordinary HTML element; in React Native, all elements will be specified by the platform React components Replacement, for example, in iOS, the
UI elements are all React components, not basic html elements like
1 |
|
5. Native styles
In the Web, using CSS styles to add styles to React components is already an inaccessible part of the development process. React generally doesn't affect the way we write CSS, and it does make dynamic creation of styles easier (via state and props), but other than that, React basically doesn't care how we handle styles.
There are a large number of ways to handle layout and styles on non-Web platforms. When we use React Native, we only need to use a standard method to handle styles. The bridge between React and the host platform includes a reduction The implementation of CSS subset, which is mainly laid out through flexbox, is as simple as possible instead of implementing all CSS rules. Unlike the Web platform, where the level of CSS support varies from browser to browser, React Native achieves consistent style rules.
6. Host platform API
The biggest difference between React using the Web environment and React Native lies in the API of the host platform.
In the Web, we often have to deal with problems caused by inconsistent and fragmented adoption of standards, and most browsers only support some core features. However, in React Native, platform-specific APIs play a huge role in providing a great native user experience. Of course, there are many more aspects to consider. The API covers many functions, from data storage to geo-services to controlling hardware devices such as cameras. APIs on unconventional platforms will be more interesting. For example, what will the API between React Native and virtual reality headsets look like?
By default, the iOS and Android versions of React Native support many commonly used features and can even support any asynchronous native API. React Native makes using the host platform API easier and more intuitive, where you can experiment freely. At the same time, be sure to think about how to match the experience of the target platform and design the interaction process in your mind. Needless to say, React Native's bridge cannot expose all APIs of the host platform.
If you need to use an unsupported feature, you can add it to React Native yourself. Also, it would be better if someone else has already integrated it, so you should check out the implementation in the community in a timely manner. It is worth noting that using platform APIs will also help with code reuse. At the same time, React components that implement platform-specific functionality are also platform-specific.
Isolating and encapsulating these components will bring greater flexibility to your application. Of course, this also works for you developing web applications. If you want to share code between React and React Native, please remember that APIs like DOM do not exist in React Native.
Related recommendations: js tutorial
The above is the detailed content of What is the difference between react and react native. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

C language functions are the basis for code modularization and program building. They consist of declarations (function headers) and definitions (function bodies). C language uses values to pass parameters by default, but external variables can also be modified using address pass. Functions can have or have no return value, and the return value type must be consistent with the declaration. Function naming should be clear and easy to understand, using camel or underscore nomenclature. Follow the single responsibility principle and keep the function simplicity to improve maintainability and readability.

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

Although C and C# have similarities, they are completely different: C is a process-oriented, manual memory management, and platform-dependent language used for system programming; C# is an object-oriented, garbage collection, and platform-independent language used for desktop, web application and game development.

Export password-protected PDF in Photoshop: Open the image file. Click "File"> "Export"> "Export as PDF". Set the "Security" option and enter the same password twice. Click "Export" to generate a PDF file.

Detailed explanation of XPath search method under DOM nodes In JavaScript, we often need to find specific nodes from the DOM tree based on XPath expressions. If you need to...

The necessity of registering VueRouter in the index.js file under the router folder When developing Vue applications, you often encounter problems with routing configuration. Special...

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.
