简体   繁体   English

如何在 React Native 移动应用程序中集成简单的 js 文件?

[英]How to integrate simple js file in react native mobile app?

I am not a react native developer, however my question is based on react native app.我不是反应原生开发人员,但我的问题是基于反应原生应用程序。 Me and my team is in a discussion to integrate an external js file into react native mobile application.我和我的团队正在讨论将外部 js 文件集成到 react 原生移动应用程序中。 The js file runs flawlessly in normal HTML. js 文件在正常的 HTML 中完美运行。 So question is can we use the same js in react native, if so how?所以问题是我们可以在 react native 中使用相同的 js,如果可以的话怎么办? Please advise with a sample code if possible.如果可能,请提供示例代码。

Thanks in advance.提前致谢。

[Update] Sample code in the js file. [更新] js文件中的示例代码。

function addition(number1, number2){
    var result = number1 + number2;
    return result.
}

Now I want to use the complete js file as it is in react native mobile app.现在我想使用完整的 js 文件,因为它在 react native 移动应用程序中。 Inside component, i should be able to use -在组件内部,我应该能够使用 -

'addition(10, 20)' '加法(10, 20)'

Yes you can.是的你可以。 But you need to study and learn React and React-Native但是你需要学习和学习ReactReact-Native

import React from 'react';
import {View,TouchableOpacity,Text} from 'react-native';

export default ()=> {
  let [sum,setSum]=React.useState(null);
  let addition=(num1,num2)=>setSum(num1+num2);

  return (
   <View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
     <Text>{sum}</Text>
     <TouchableOpacity
        style={{padding:20, backgroundColor:'tomato'}}
        onPress={()=>addition(10,20)}
     >
        <Text>Run</Text>
     </TouchableOpacity>
   </View>
  )
}

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

相关问题 如何将Fabric js与React本机集成? - How to integrate Fabric js with React native? 如何将 Crashlytics 与 React Native 应用程序集成 - How to Integrate Crashlytics with React Native app 如何将React-Native移动应用转换为React Web应用? - How to convert React-Native mobile app to React web app? 如何将 Google 标签管理器与 React Native 应用程序集成? - How to integrate Google Tag Manager with React Native app? React Native:如何集成Stripe? - React Native: How to integrate Stripe? 如何在 React Native 中集成 QuickBlox? - How to integrate QuickBlox in react native? 在使用 React Native 构建的移动应用程序中包含外部 javascript 文件 - Include external javascript file in mobile app built using react native React Native:如何将 props 变量从其他 js 文件传递到 app.js 文件 - React Native: How to pass a props variable from other js file to app.js file 如何将后台 JS animation 集成到我的反应应用程序中? - How do I integrate a background JS animation into my react app? 如果移动应用程序要在React Native中使用,在React JS中设置Web应用程序是否有优势 - Is there an advantage to setting up web app in React JS if mobile app is going to be in React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM