我已经开始学习React出于好奇,想知道React和React Native之间的区别-虽然不能找到一个满意的答案使用谷歌。React和React Native似乎有相同的格式。它们的语法完全不同吗?
当前回答
React Native是一个JavaScript框架,它提供了编写多平台应用程序(如iOS或Android)所需的一切。
ReactJS是一个JavaScript库,用于构建web界面和构建您的网站。
其他回答
区别很简单。
我们使用React开发web应用程序,使用React Native开发移动应用程序。
React更专注于改进UI(用户界面),而RN则为所有操作系统共享一个公共逻辑层。这为现在已经处理了很长一段时间的问题提供了解决方案,例如开发效率低、部署时间较慢和开发人员生产力较低。
需要注意的是,React是一个用于web开发的库,而React Native是一个平台。
另一件有趣的事情是,当您想要使用RN时,您拥有启动项目所需的一切。另一方面,用React创建一个新项目意味着你只选择了构建web应用程序所需的众多库中的一个。
你可以在那篇文章中找到更多有用的信息: https://pagepro.co/blog/react-native-faq-all-you-need-to-know
react是一个核心框架,旨在构建基于响应式模式的组件,你可以把它看作是MVC中的V,尽管我想说的是,react确实带来了不同的感觉,特别是如果你不太熟悉响应式的概念。
ReactNative是另一层,旨在为Android和iOS平台提供一套常见的组件。所以代码看起来基本上与ReactJS相同,因为它是ReactJS,但它是在移动平台上原生加载的。你也可以根据操作系统将更复杂的和平台相关的API与Java/Objective-C/Swift连接起来,并在React中使用它。
React-Native是一个框架,其中ReactJS是一个javascript库,可以用于您的网站。
React-native提供了默认的核心组件(图像,文本),其中React提供了一堆组件并使它们协同工作。
简单来说 ReactJS是父库,它返回一些东西来渲染每个主机环境(浏览器,移动,服务器,桌面等)。 除了渲染,它还提供了其他方法,如生命周期钩子..等。
在浏览器中,它使用另一个库react-dom来呈现DOM元素。 在移动端,它使用React-Native组件来呈现特定平台(IOS和Android)的本地UI组件。 所以,
React + React -dom = web开发
React + React -native =移动开发
反应:
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/
推荐文章
- 使用jQuery以像素为整数填充或边距值
- 检查是否选择了jQuery选项,如果没有选择默认值
- TypeScript错误:属性“X”在类型“Window”上不存在
- Next.js React应用中没有定义Window
- 如何重置笑话模拟函数调用计数之前,每次测试
- 如何强制一个功能React组件渲染?
- 反应-正确的方式传递表单元素的状态兄弟/父元素?
- 在javascript中从平面数组构建树数组
- 将Dropzone.js与其他字段集成到现有的HTML表单中
- 如何在AngularJS中观察路由变化?
- JavaScript DOM删除元素
- 将dd-mm-yyyy字符串转换为日期
- Javascript复选框onChange
- Javascript函数前导bang !语法
- 如何在页面上遍历所有DOM元素?