我已经开始学习React出于好奇,想知道React和React Native之间的区别-虽然不能找到一个满意的答案使用谷歌。React和React Native似乎有相同的格式。它们的语法完全不同吗?


当前回答

为了回应上面@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 Native主要是用JavaScript开发的,这意味着你需要开始的大部分代码都可以跨平台共享。React Native将使用本地组件进行渲染。React Native应用程序是用目标平台所需的语言开发的,iOS的Objective-C或Swift, Android的Java等。所编写的代码不是跨平台共享的,它们的行为各不相同。他们可以直接使用平台提供的所有功能,不受任何限制。

React是Facebook开发的一个开源JavaScript库,用于构建用户界面。它用于处理web和移动应用程序的视图层。ReactJS用于创建可重用的UI组件。它是目前It领域最流行的JavaScript库之一,它有强大的基础和庞大的社区支持。如果你学习ReactJS,你需要有JavaScript, HTML5和CSS的知识。

React是React Native和React DOM的基本抽象,所以如果你要使用React Native,你还需要React…与web相同,但不是React Native,你将需要React DOM。

由于React是基本抽象,一般语法和工作流是相同的,但你将使用的组件是非常不同的,因此你需要学习这些差异,这是内联React,所谓的moto,即“一次学习,随处编写”,因为如果你知道React(基本抽象),你可以简单地学习平台之间的差异,而不学习另一种编程语言,语法和工作流。

反应

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 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

React本质上是Facebook自己开发的。它实际上是在2013年进入科技界的。React是一个JS库,不是一个框架。React最值得注意的一点是它能够创建前端和后端。

React NATIVE只是一个移动开发平台。在使用React native之前,你需要知道Android的Java或iPhone和iPad的Objective-C来创建原生React应用程序。简单地说,React是Webdev技术,React- native是移动开发技术。