我已经开始学习React出于好奇,想知道React和React Native之间的区别-虽然不能找到一个满意的答案使用谷歌。React和React Native似乎有相同的格式。它们的语法完全不同吗?
当前回答
REACT是一个Javascript库,用于构建像Facebook这样的大型/小型界面web应用程序。
REACT NATIVE是一个Javascript框架,用于开发Android、IOS和Windows Phone上的原生移动应用程序。
两者都是由Facebook开源的。
其他回答
为了回应上面@poshest的评论,这里有一个React Native版本的时钟代码,之前在React中发布(抱歉,我无法直接评论这部分,否则我会在那里添加代码):
React Native代码示例
import { AppRegistry } from 'react-native';
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
class Clock extends 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 (
<View style={styles.container}>
<Text style={styles.sectionTitle}>Hello, world!</Text>
<Text style={styles.sectionDescription}>It is {this.state.date.toLocaleTimeString()}.</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
justifyContent: 'center',
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: 'black',
alignSelf: 'center',
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: 'darkgrey',
alignSelf: 'center',
},
});
AppRegistry.registerComponent("clock", () => Clock);
注意,样式完全是我的选择,并不寻求直接复制在React代码中使用的<h1>和<h2>标记。
React用于在浏览器中工作的web应用程序。 React Native用于android和IOS应用程序,这些应用程序在移动应用程序中工作。
React is a framework for building applications using JavaScript. React Native is an entire platform allowing you to build native, cross-platform mobile apps, and React.js is a JavaScript library you use for constructing a high performing UI layer. React.js is the heart of React Native, and it embodies all React’s principles and syntax, so the learning curve is easy. The platform is what gave rise to their technical differences. Like the browser code in React is rendered through Virtual DOM while React Native uses Native API’s to render components on mobile. React uses HTML and with React Native, you need to familiarize yourself with React Native syntax. React Native doesn’t use CSS either. This means you’ll have to use the animated API which comes with React Native to animate different components of your application.
最重要的是,React是为你的web界面构建动态,高性能,响应性UI的理想选择,而React Native是为了给你的移动应用程序一个真正的原生感觉。
雷夫:what-is-the-difference-between-react-js-and-react-native
ReactJS是一个用于构建UI组件层次结构的框架。每个组件都有状态和道具。数据通过道具从顶层流向底层组件。在顶级组件中使用事件处理程序更新状态。
React native使用React框架为移动应用程序构建组件。React native为iOS和Android平台提供了一组基本的组件。React Native中的一些组件是Navigator, TabBar, Text, TextInput, View, ScrollView。这些组件内部使用原生iOS UIKit和Android UI组件。React native还允许使用NativeModules,其中用iOS的objective - c和Android的Java编写的代码可以在JavaScript中使用。
注意:React Native作为一个框架,允许以类似HTML和CSS的语法开发移动应用程序。原生组件在原生开发中有效地取代了HTML。
React是一个声明性的、高效的、灵活的JavaScript库,用于构建用户界面。你的组件告诉React你想要呈现什么——然后当你的数据发生变化时,React会有效地更新并呈现正确的组件。这里,ShoppingList是一个React组件类,或者React组件类型。
React Native应用程序是真正的移动应用程序。使用React Native,你不需要构建“移动web应用程序”、“HTML5应用程序”或“混合应用程序”。你构建了一个真正的移动应用,它与使用Objective-C或Java构建的应用没有什么区别。React Native使用与常规iOS和Android应用相同的基本UI构建块。
更多信息
推荐文章
- 我如何使用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>表单字段被禁用时提交?