Javascript React本机可触摸不透明度函数

Javascript React本机可触摸不透明度函数,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我的React原生应用程序中有两个函数,我需要我的TouchableOpacity在按下时调用这两个函数。为此,我尝试在onPress方法中简单地使用一个arrow函数,两个函数都在其中,但这不起作用。我想这与范围有关,但我不确定。当仅将这两个函数传递到onPress方法中时,它们都能正常工作。下面是代码(为了便于阅读,我做了很多修改),请帮忙 export class CreateItem extends React.Component { constructor(props){ su

我的React原生应用程序中有两个函数,我需要我的TouchableOpacity在按下时调用这两个函数。为此,我尝试在onPress方法中简单地使用一个arrow函数,两个函数都在其中,但这不起作用。我想这与范围有关,但我不确定。当仅将这两个函数传递到onPress方法中时,它们都能正常工作。下面是代码(为了便于阅读,我做了很多修改),请帮忙

export class CreateItem extends React.Component {
constructor(props){
    super(props);
}

sendData = () => {
    itemData = this.state.item;
    this.props.action(itemData); //the action function alters the parent state (this function works fine every other time)
}
render(){
return(
    <TouchableOpacity
    onPress={() => {
    this.sendData;
    this.props.hide; //This function is passed from the parent and works fine in other scenarios 
    }}
    >
        <Text>Add Item</Text>
    </TouchableOpacity>
)
}
导出类CreateItem扩展React.Component{
建造师(道具){
超级(道具);
}
sendData=()=>{
itemData=this.state.item;
this.props.action(itemData);//action函数更改父状态(此函数每隔一次工作正常)
}
render(){
返回(
{
这是发送数据;
this.props.hide;//此函数是从父级传递的,在其他情况下可以正常工作
}}
>
添加项
)
}

您错过了函数的括号

export class CreateItem extends React.Component {
constructor(props){
    super(props);
}

sendData = () => {
    itemData = this.state.item;
    this.props.action(itemData); //the action function alters the parent state (this function works fine every other time)
}
render(){
    return(
        <TouchableOpacity
            onPress={() => {
                this.sendData();
                this.props.hide(); //This function is passed from the parent and works fine in other scenarios 
            }}
        >
            <Text>Add Item</Text>
        </TouchableOpacity>
    )
}
导出类CreateItem扩展React.Component{
建造师(道具){
超级(道具);
}
sendData=()=>{
itemData=this.state.item;
this.props.action(itemData);//action函数更改父状态(此函数每隔一次工作正常)
}
render(){
返回(
{
这是sendData();
this.props.hide();//此函数是从父级传递的,在其他情况下可以正常工作
}}
>
添加项
)
}

可能重复@Simons0n我已经试过了,但都没有成功。我相信我展示的代码实际上是在这个问题的第二个答案后面(使用箭头函数)。我认为我的代码可能无法工作,因为我的两个函数都是由父类传递的?缺少括号:
()=>{this.sendData();this.props.hide();}
。不多不少。