我已经开始学习React出于好奇,想知道React和React Native之间的区别-虽然不能找到一个满意的答案使用谷歌。React和React Native似乎有相同的格式。它们的语法完全不同吗?
当前回答
ReactJS是一个javascript库,用于构建web界面。你需要一个像webpack这样的捆绑器,并尝试安装你建立网站所需的模块。
React Native是一个javascript框架,它包含了编写多平台应用程序(如iOS或Android)所需的一切。你需要安装xcode和android studio来构建和部署你的应用。
与ReactJS不同,React-Native不使用HTML,而是使用类似的组件,你可以跨ios和android来构建你的应用程序。这些组件使用真正的本地组件来构建ios和android应用程序。因此,React-Native应用程序感觉真实,不像其他混合开发平台。组件还增加了代码的可重用性,因为你不需要在ios和android上再次创建相同的用户界面。
其他回答
ReactJS是一个JavaScript库,支持前端web和在服务器上运行,用于构建用户界面和web应用程序。它遵循可重用组件的概念。
React Native是一个移动框架,它利用了主机上可用的JavaScript引擎,允许你在JavaScript中为不同的平台(iOS, Android和Windows mobile)构建移动应用程序,允许你使用React js构建可重用的组件,并与本地组件通信
两者都遵循JavaScript的JSX语法扩展。它编译为React。createElement在底层调用。JSX深入
两者都是由Facebook开源的。
反应
React is used for creating websites, web apps, SPAs etc. React is a Javascript library used for creating UI hierarchy. It is responsible for rendering of UI components, It is considered as V part Of MVC framework. React’s virtual DOM is faster than the conventional full refresh model, since the virtual DOM refreshes only parts of the page, Thus decreasing the page refresh time. React uses components as basic unit of UI which can be reused this saves coding time. Simple and easy to learn. React Native React Native is a framework that is used to create cross-platform Native apps. It means you can create native apps and the same app will run on Android and ios. React native have all the benefits of ReactJS React native allows developers to create native apps in web-style approach.
React Native是一个JavaScript框架,它提供了编写多平台应用程序(如iOS或Android)所需的一切。
ReactJS是一个JavaScript库,用于构建web界面和构建您的网站。
反应:
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/
一些区别如下: 1- React-Native是一个用于创建移动应用程序的框架,其中ReactJS是一个javascript库,可以用于您的网站。 2- React- native不使用HTML来渲染应用程序,而React使用。 3- React- native只用于开发移动应用程序,而React用于网站和移动。
推荐文章
- 我如何使用Jest模拟JavaScript的“窗口”对象?
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- React组件中使用TypeScript的默认属性值
- 我如何等待一个承诺完成之前返回一个函数的变量?
- 在JavaScript中根据键值查找和删除数组中的对象
- 使嵌套JavaScript对象平放/不平放的最快方法
- 如何以及为什么'a'['toUpperCase']()在JavaScript工作?
- 有Grunt生成index.html不同的设置
- 文档之间的区别。addEventListener和window。addEventListener?
- 如何检查动态附加的事件监听器是否存在?
- 如何写setTimeout与参数Coffeescript
- 将JavaScript字符串中的多个空格替换为单个空格
- JavaScript: override alert()
- 重置setTimeout
- 如何确保<select>表单字段被禁用时提交?