在React native中,如何在没有构造函数的情况下从另一个函数调用函数



我需要从我的函数调用">RegisterTaster";我的职能endRegisterAlert";但实际上我没有使用构造函数,因为我在react native中像const一样使用该类。

如何调用函数

const Validator=(props)=>{
async function RegisterTaster(){
//do something...
endRegisterAlert();
}
function endRegisterAlert(){
//do something
}
return(
<Button onPress={async ()=> await RegisterTaster() }> 
<Text >Register</Text> 
</Button
);
}
export default Validator;

就这么做吧。

const Validator=(props)=>{
async function RegisterTaster(){
//do something...
endRegisterAlert();
}
function endRegisterAlert(){
//do something
}
return(
<Button onPress={RegisterTaster}> 
<Text >Register</Text> 
</Button
);
}

您使用的是基于函数的React组件。

除了您正在等待异步函数的部分之外,一切都是正确的。

这样做:

return(
<Button onPress={RegisterTaster}> 
<Text>Register</Text> 
</Button
);

或:

return(
<Button onPress={() => RegisterTaster()}> 
<Text>Register</Text> 
</Button
);

不管怎样,它都应该起作用。

相关内容

最新更新