繁体   English   中英

响应本机:在onPress上调用多个函数

[英]react native : calling multiple functions onPress

是否可以使用onPress按钮调用多个functions(not arrow function)

我知道我可以像这样调用多个箭头函数:

onPress={() => { this.functionOne(); this.functionTwo();}}

但是,如果我想在没有arrow function情况下调用多个arrow function怎么办? 我试过了,但这行不通。

onPress={this.functionOne, this.functionTwo}

最好的方法是使用一个函数来调用所有函数,

func = () => {
   this.functionOne(); 
   this.functionTwo();
}

onPress={this.func}

或者您可以传递函数数组并在子组件中调用它们,

家长:

onPress=[this.functionOne, this.functionTwo]

儿童:

this.props.onPress.map(func=>{
   func()
})

暂无
暂无

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

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