我正在尝试从警报按钮“是”调用并将值传递给我的函数,但它不起作用,函数未接收值并在我使用函数值时给出未定义的错误。这是我的代码
const sendemail = async ({ email, hash, password }) => {
console.log(email); //getting Error here undefined email
}
Alert.alert(
"Account is not activated",
"kindly check your email box and verify your account.Do you want to Resend Verification Email ?",
[
{
text: "Yes",
onPress: () =>
this.sendemail(
email,
hash,
password
),
},
{
text: "No",
// onPress: () => console.log("No"),
},
]
);
答案 0 :(得分:2)
在 sendemail 调用中,您没有传递对象,而是传递了三个参数。然后你试图在方法中解构一个对象。 试试这个:(我只删除了方法定义中的解构)
const sendemail = async ( email, hash, password ) => {
console.log(email);
}
Alert.alert(
"Account is not activated",
"kindly check your email box and verify your account.Do you want to Resend Verification Email ?",
[
{
text: "Yes",
onPress: () =>
this.sendemail(
email,
hash,
password
),
},
{
text: "No",
// onPress: () => console.log("No"),
},
]
);
答案 1 :(得分:0)
尝试消除
"() =>" 来自 Yes 的 onPress 方法,如果没有尝试在 "() =>" 中添加参数,它看起来像
onPress: (e, h, p) => 这个.sendmail( 电子, H, 磷 ),