我已经开始学习React出于好奇,想知道React和React Native之间的区别-虽然不能找到一个满意的答案使用谷歌。React和React Native似乎有相同的格式。它们的语法完全不同吗?
当前回答
反应本地
它是一个使用JavaScript构建本地应用程序的框架。 它编译为本地应用程序组件,这使它成为可能 构建原生移动应用程序。 不需要彻底检查你的旧应用程序。你所要做的就是添加React 将本地UI组件添加到现有应用程序代码中,而不必这样做 重写。
js的反应
它既支持前端web,也支持在服务器上运行 构建用户界面和web应用程序。 它还允许我们创建可重用的UI组件。 你可以在React JS中重用代码组件,节省大量时间。
其他回答
反应:
React是一个声明性的、高效的、灵活的JavaScript库 构建用户界面。
本机反应:
React Native lets you build mobile apps using only JavaScript. It uses the same design as React, letting you compose a rich mobile UI from declarative components. With React Native, you don't build a “mobile web app”, an “HTML5 app”, or a “hybrid app”. You build a real mobile app that's indistinguishable from an app built using Objective-C or Java. React Native uses the same fundamental UI building blocks as regular iOS and Android apps. You just put those building blocks together using JavaScript and React. React Native lets you build your app faster. Instead of recompiling, you can reload your app instantly. With hot reloading, you can even run new code while retaining your application state. Give it a try - it's a magical experience. React Native combines smoothly with components written in Objective-C, Java, or Swift. It's simple to drop down to native code if you need to optimize a few aspects of your application. It's also easy to build part of your app in React Native, and part of your app using native code directly - that's how the Facebook app works.
基本上React是web应用视图的UI库,使用javascript和JSX, React native是React之上的一个额外库,用于iOS和Android设备的原生应用。
React代码示例:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
);
}
componentWillUnmount() {
clearInterval(this.timerID);
}
tick() {
this.setState({
date: new Date()
});
}
render() {
return (
<div>
<h1>Hello, world!</h1>
<h2>It is {this.state.date.toLocaleTimeString()}.</h2>
</div>
);
}
}
ReactDOM.render(
<Clock />,
document.getElementById('root')
);
React Native代码示例:
import React, { Component } from 'react';
import { Text, View } from 'react-native';
class WhyReactNativeIsSoGreat extends Component {
render() {
return (
<View>
<Text>
If you like React on the web, you'll like React Native.
</Text>
<Text>
You just use native components like 'View' and 'Text',
instead of web components like 'div' and 'span'.
</Text>
</View>
);
}
}
有关React的更多信息,请访问facebook团队创建的官方网站:
https://reactjs.org/
有关React Native的更多信息,请访问下面的React Native网站:
https://reactnative.dev/
我们无法准确地比较它们。用例中存在差异。
(2018更新)
反应
React的主要关注点是Web开发。
React’s virtual DOM is faster than the conventional full refresh model, since the virtual DOM refreshes only parts of the page. You can reuse code components in React, saving you a lot of time. (You can in React Native too.) As a business: The rendering of your pages completely, from the server to the browser will improve the SEO of your web app. It improves the debugging speed making your developer’s life easier. You can use hybrid mobile app development, like Cordova or Ionic, to build mobile apps with React, but is more efficiently building mobile apps with React Native from many points.
反应本地
React的扩展,针对移动开发。
Its main focus is all about Mobile User Interfaces. iOS & Android are covered. Reusable React Native UI components & modules allow hybrid apps to render natively. No need to overhaul your old app. All you have to do is add React Native UI components into your existing app’s code, without having to rewrite. Doesn't use HTML to render the app. Provides alternative components that work in a similar way, so it wouldn't be hard to understand them. Because your code doesn’t get rendered in an HTML page, this also means you won’t be able to reuse any libraries you previously used with React that renders any kind of HTML, SVG or Canvas. React Native is not made from web elements and can’t be styled in the same way. Goodbye CSS Animations!
希望我帮到你了:)
React Native是为移动应用程序,而React是为网站(前端)。这两个框架都是Facebook发明的。React Native是一个跨平台的开发框架,这意味着你可以为IOS和Android编写几乎相同的代码,而且它可以工作。我个人对React Native了解更多,所以我就到此为止。
首先是相似之处:React和React Native (RN)都是为了创建灵活的用户界面而设计的。这些框架有很多好处,但最基本的一点是它们是为ui开发而设计的。Facebook在React之后几年开发了RN。
反应: Facebook设计的这个框架几乎就像在HTML/XML中编写JavaScript,这就是为什么标签被称为“JSX”(JavaScript XML),类似于我们熟悉的类似HTML的标签,如<div>或<p>。React的一个标志是大写字母标记,它表示自定义组件,例如<MyFancyNavbar />,它也存在于RN中。然而,React使用DOM。DOM是为HTML而存在的,因此React是用于web开发的。
React Native: RN does not use HTML, and therefore is not used for web development. It is used for... virtually everything else! Mobile development (both iOS & Android), smart-devices (e.g. watches, TVs), augmented reality, etc. As RN has no DOM to interact with, instead of using the same sort of HTML tags used in React, it uses its own tags which are then compiled into other languages. For example, instead of <div> tags, RN developers use RN's built-in <View> tag, which compiles into other native code under the hood (e.g. android.view on Android; and UIView on iOS).
简而言之:它们非常相似(对于UI开发),但用于不同的媒介。
Reactjs使用react-dom而不是浏览器dom,而react native使用虚拟dom,但两者使用相同的语法,即如果你可以使用Reactjs,那么你可以使用react native。因为你在reactjs中使用的大多数库在react native中都是可用的,比如你的react导航和其他常见的库。
推荐文章
- 给一个数字加上st, nd, rd和th(序数)后缀
- 如何以编程方式触发引导模式?
- setTimeout带引号和不带括号的区别
- 在JS的Chrome CPU配置文件中,'self'和'total'之间的差异
- 用javascript检查输入字符串中是否包含数字
- 如何使用JavaScript分割逗号分隔字符串?
- 在Javascript中~~(“双波浪号”)做什么?
- 谷歌chrome扩展::console.log()从后台页面?
- 未捕获的SyntaxError:
- [].slice的解释。调用javascript?
- jQuery日期/时间选择器
- 我如何预填充一个jQuery Datepicker文本框与今天的日期?
- npm犯错!代码UNABLE_TO_GET_ISSUER_CERT_LOCALLY
- 数组的indexOf函数和findIndex函数的区别
- 反应-显示加载屏幕,而DOM是渲染?