javascript - 如何在本机反应中从警报按钮传递值以发挥作用
问题描述
我正在尝试从警报按钮“是”调用并将值传递给我的函数,但它不起作用,当我使用函数值时,函数没有接收值并给出未定义的错误。这是我的代码
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"),
},
]
);
解决方案
在 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"),
},
]
);
推荐阅读
- cakephp - 如何在 CakePHP 中验证所需的关联存在?
- c++ - 在 OpenCV 中以 PLY 格式计算 3D 模型上的 ORB 描述符的问题
- sql - 在查询中将非常大的数字转换为 NULL
- c# - 从使用 iframe c# 的网页中抓取数据
- ajax - 将控制器中的字符串发送到视图中的 Ajax
- android - Hilt 构建失败
- android - Android - 在 src/main 目录中读写文件
- ubuntu - 为个人计算生成完全可用的 Debian VM 的最小 Vagrant 脚本
- java - 当我收到此 java.lang 错误时,如何使用 Gmail 使用 R 发送电子邮件
- typescript - 在Angular中搜索时如何转到表格的第一页?