![](/img/trans.png)
[英]How to get a return value from async function to a variable in React Native?
[英]React Native How to get return value from two function
我在反应原生 class 组件中有两个 function 。 我尝试通过调用 test1() 来获取返回值,但它没有显示返回值。 如果直接调用 test2(),我可以得到返回值。 但是这里在 function 中会有很多 if else 条件和返回值,所以我需要调用 function test1( )...有人可以帮忙吗?
test1(){
this.test2()
}
test2(){
return(
<Text>Testing123</Text>
)
}
render{
return(
<View>
{this.test1()}
</<View>
)
}
您需要在 test1 中返回从 test2 返回的值。
test1(){
return(this.test2())
}
test2(){
return(
<Text>Testing123</Text>
)
}
render{
return(
<View>
{this.test1()}
</<View>
)
}
我还建议您使用箭头函数而不是普通函数。
const test1 = () => {
//Code
}
or
test1 = () => {
//Code
}
而不是
test1(){
//Code
}
问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.