[英]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
但是你需要学习和学习
React
和React-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.