本机反应:在onPress

时间:2019-06-14 02:21:35

标签: javascript react-native

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

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

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

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

onPress={this.functionOne, this.functionTwo}

1 个答案:

答案 0 :(得分:4)

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

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

onPress={this.func}

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

父母:

onPress=[this.functionOne, this.functionTwo]

孩子:

this.props.onPress.map(func=>{
   func()
})
相关问题