本文翻译自:What is the difference between React Native and React?
I have started to learn React out of curiosity and wanted to know the difference between React and React Native - though could not find a satisfactory answer using Google. 我已经出于好奇而开始学习React ,并想知道React和React Native之间的区别-尽管使用Google找不到满意的答案。 React and React Native seems to have the same format. React和React Native似乎具有相同的格式。 Do they have completely different syntax? 它们的语法完全不同吗?
#1楼
参考:https://stackoom.com/question/2LLrC/React-Native和React之间有什么区别
#2楼
ReactJS is a JavaScript library, supporting both front-end web and being run on a server, for building user interfaces and web applications. ReactJS是一个JavaScript库,它支持前端Web并在服务器上运行,用于构建用户界面和Web应用程序。
React Native is a mobile framework that compiles to native app components, allowing you to build native mobile applications for different platforms (iOS, Android, and Windows Mobile) in JavaScript that allows you to use ReactJS to build your components, and implements ReactJS under the hood. React Native是一个可编译为本机应用程序组件的移动框架,允许您使用JavaScript构建适用于不同平台(iOS,Android和Windows Mobile)的本机移动应用程序,从而允许您使用ReactJS来构建组件,并在罩。
Both are open sourced by Facebook. 两者均由Facebook开源。
#3楼
ReactJS is a framework for building an hierarchy of UI components. ReactJS是用于构建UI组件层次结构的框架。 Each component has state and props. 每个组件都有状态和道具。 Data flows from the top to low-level components via props. 数据通过道具从顶层流向底层组件。 The state is updated in the top-level component using event handlers. 使用事件处理程序在顶级组件中更新状态。
React native uses React framework for building components for mobile apps. React native使用React框架为移动应用程序构建组件。 React native provides a basic set of components for both iOS and Android platforms. React native提供了适用于iOS和Android平台的一组基本组件。 Some of the components in React Native are Navigator, TabBar, Text, TextInput, View, ScrollView. React Native中的一些组件是Navigator,TabBar,Text,TextInput,View,ScrollView。 These components use native iOS UIKit and Android UI components internally. 这些组件在内部使用本机iOS UIKit和Android UI组件。 React native also allows NativeModules where code written in ObjectiveC for iOS and Java for Android can be used within JavaScript. React native还允许使用NativeModules,在JavaScript中可以使用用iOS的ObjectiveC和Android的Java编写的代码。
#4楼
Google can't explain this to you, as you said, but Google would be so happy if they invented React. 正如您所说,Google无法向您解释这一点,但是Google会很高兴如果他们发明了React。
Here is the React project . 这是React项目 。
At Facebook, they invented React so JavaScript can manipulate the website DOM faster using the virtual DOM model. 在Facebook,他们发明了React,因此JavaScript可以使用虚拟DOM模型更快地操作网站DOM。
DOM full refresh is slower compared to the React virtual-dom model , which refreshes only parts of the page (read: partial refresh). 与React虚拟域模型相比,DOM完全刷新的速度较慢,后者仅刷新页面的一部分(阅读:部分刷新)。
As you may understand from this video , Facebook did not invent React because they understood immediately that the partial refresh would be faster than the conventional one. 正如您从该视频中所了解的那样,Facebook并未发明React,因为他们立即了解到部分刷新将比传统刷新更快。 Originally they needed a way to reduce Facebook application re-build time and luckily this brought the partial DOM refresh to life. 最初,他们需要一种减少Facebook应用程序重建时间的方法,幸运的是,这使部分DOM焕然一新。
React native is just a consequence of React. React native只是React的结果。 It is a platform to build native apps using JavaScript. 这是一个使用JavaScript构建本机应用程序的平台。
Prior to React native you needed to know Java for Android or Objective-C for iPhone and iPad to create native apps. 在使用React native之前,您需要了解Android的Java或iPhone和iPad的Objective-C才能创建本地应用。
With React Native it is possible to mimic the behavior of the native app in JavaScript and at the end, you will get platform specific code as the output. 使用React Native,可以模仿JavaScript中本机应用程序的行为,最后,您将获得平台特定的代码作为输出。 You may even mix the native code with the JavaScript if you need to optimize your application further. 如果您需要进一步优化应用程序,甚至可以将本机代码与JavaScript混合使用。
As Olivia Bishop said in the video , 85% of the React native code base can be shared among platforms. 正如Olivia Bishop在视频中所说, React本机代码库的85%可以在平台之间共享。 These would be the components applications typically use and the common logic. 这些将是应用程序通常使用的组件和通用逻辑。
15% of the code is platform specific. 15%的代码是特定于平台的。 The platform-specific JavaScript is what gives the platform flavor ( and makes the difference in the experience ). 特定于平台的JavaScript赋予了平台风味(并带来了与众不同的体验)。
The cool thing is this platform specific code — is already written, so you just need to use it. 最酷的是该平台特定的代码-已经编写好了,因此您只需要使用它即可。
#5楼
React Js is a Javascript Library where you can develop and run faster web applications using React . React Js是一个Javascript库,您可以在其中使用React来开发和运行更快的Web应用程序。
React Native lets you build mobile apps using only JavaScript,it is used for Mobile application development . React Native允许您仅使用JavaScript构建移动应用程序,用于移动应用程序开发。 more info here https://facebook.github.io/react-native/docs/getting-started.html 更多信息在这里https://facebook.github.io/react-native/docs/getting-started.html
#6楼
React-Native is a framework, where ReactJS is a javascript library you can use for your website. React-Native是一个框架,其中ReactJS是可用于您的网站的javascript库。
React-native provides default core components (images, text), where React provides a bunch of components and make them work together. React-native提供默认的核心组件(图像,文本),其中React提供了许多组件并使它们协同工作。