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
import { DatePickerIOS } from 'react-native';
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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

Netflixusesacustomframeworkcalled"Gibbon"builtonReact,notReactorVuedirectly.1)TeamExperience:Choosebasedonfamiliarity.2)ProjectComplexity:Vueforsimplerprojects,Reactforcomplexones.3)CustomizationNeeds:Reactoffersmoreflexibility.4)Ecosystema

The React ecosystem includes state management libraries (such as Redux), routing libraries (such as ReactRouter), UI component libraries (such as Material-UI), testing tools (such as Jest), and building tools (such as Webpack). These tools work together to help developers develop and maintain applications efficiently, improve code quality and development efficiency.

The advantages of React are its flexibility and efficiency, which are reflected in: 1) Component-based design improves code reusability; 2) Virtual DOM technology optimizes performance, especially when handling large amounts of data updates; 3) The rich ecosystem provides a large number of third-party libraries and tools. By understanding how React works and uses examples, you can master its core concepts and best practices to build an efficient, maintainable user interface.

React is a front-end framework for building user interfaces; a back-end framework is used to build server-side applications. React provides componentized and efficient UI updates, and the backend framework provides a complete backend service solution. When choosing a technology stack, project requirements, team skills, and scalability should be considered.

React's main functions include componentized thinking, state management and virtual DOM. 1) The idea of componentization allows splitting the UI into reusable parts to improve code readability and maintainability. 2) State management manages dynamic data through state and props, and changes trigger UI updates. 3) Virtual DOM optimization performance, update the UI through the calculation of the minimum operation of DOM replica in memory.

React's future will focus on the ultimate in component development, performance optimization and deep integration with other technology stacks. 1) React will further simplify the creation and management of components and promote the ultimate in component development. 2) Performance optimization will become the focus, especially in large applications. 3) React will be deeply integrated with technologies such as GraphQL and TypeScript to improve the development experience.

Advantages of integrating Bootstrap into React projects include: 1) rapid development, 2) consistency and maintainability, and 3) responsive design. By directly introducing CSS files or using the React-Bootstrap library, you can use Bootstrap's components and styles efficiently in your React project.

React is a JavaScript library developed by Meta for building user interfaces, with its core being component development and virtual DOM technology. 1. Component and state management: React manages state through components (functions or classes) and Hooks (such as useState), improving code reusability and maintenance. 2. Virtual DOM and performance optimization: Through virtual DOM, React efficiently updates the real DOM to improve performance. 3. Life cycle and Hooks: Hooks (such as useEffect) allow function components to manage life cycles and perform side-effect operations. 4. Usage example: From basic HelloWorld components to advanced global state management (useContext and
