简体   繁体   English

如何在React Native中重用React JS组件

[英]How to reuse the React JS component in React Native

I am new to React JS . 我是React JS新手。 I am trying to build a web application which should also work on mobile (Android and IOS) so thought of using react js for web application and created few components. 我正在尝试构建一个Web应用程序,该应用程序也可以在移动设备(Android和IOS)上运行,因此想到将react js用于web application并创建了一些组件。 so is it possible to use the React js component in React native . 所以可以在React native使用React js组件。

It's good that you plan in advance. 你提前做好计划是件好事。 100% matching between JS and Native won't be possible, but with careful planning, you could get to reuse a good deal. JS和Native之间100%匹配是不可能的,但经过仔细的规划,你可以重复使用。

You may want to take a look at React Native Web project that mirrors Native-specific components for Web (eg View, Image, Text, etc). 您可能需要查看反映Web的特定于本机的组件的React Native Web项目(例如,视图,图像,文本等)。

I suggest building a simple prototype in React JS and then in React Native so you get some understanding of the differences in the two ecosystems. 我建议在React JS中构建一个简单的原型,然后在React Native中构建一个简单的原型,这样你就可以了解这两个生态系统的差异。 Having a hands on experience will prove more beneficial than any writeup :) 拥有实践经验将证明比任何写作更有益:)

ReactNative is a set of real native Components like View , TextInput TouchableHighlight and more . ReactNative是一组像真正的本地组件的ViewTextInput TouchableHighlight更多 It is also a platform which let you run javascript code to control these. 它也是一个平台,让您运行JavaScript代码来控制这些。

There is no WebView like in Cordova, what you get is a native App with native views. Cordova中没有WebView,你得到的是具有原生视图的本机应用程序。

But that means, that you can still have some or your domain logic written in JS which you can use the same way in your Web App. 但这意味着,您仍然可以使用JS编写的某些或您的域逻辑,您可以在Web App中使用相同的方式。

For example you have a Login Screen for iOS, but all the necessary stuff for your server calls, can go into a separate module eg api/auth.js , which is shareable between web, ios, android, iot.. what ever. 例如,你有一个iOS的登录屏幕,但你的服务器调用的所有必要的东西,可以进入一个单独的模块,例如api/auth.js ,它可以在web,ios,android,iot之间分享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM