firebase - 当来自 rnfirebase 的 firestore 包时,数据未存储在 Firestore 中
问题描述
我为我的 React 本机应用程序使用了 @react-native-firebase/firestore 包。我也安装了我的 firebase/app,并按照 firebase 网页中的所有安装步骤进行操作。但我无法将数据存储到我的 Firestore 中。这是我使用的代码。
import firestore from '@react-native-firebase/firestore';
export const storeData = async (userDetails) => {
let userName = userDetails.userName;
let storeSuccess = await firestore()
.collection('Users')
.doc('123')
.set({
username: userDetails.userName,
userselfie: userDetails.userSelfie,
LP: userDetails.LPImage,
bill: userDetails.BillImage,
customercontact: userDetails.customerContact,
date: userDetails.date,
time: userDetails.time,
})
.then(() => console.log('success'))
.catch((error) => {
error.message && alert(error.message);
console.log(
'Something went wrong while adding user data to firestore: ',
error,
);
return 'error';
});
return storeSuccess;
};
我已经完成了所有工作,甚至调用了上述函数,但我得到了{"_U": 0, "_V": 0, "_W": null, "_X": null}
来自 firestore 函数的响应。
解决方案
使用async/await
withPromise.then()
可能会导致这种意外行为。为了修复您的功能,请删除async/await
并保留then()
如下符号:
export const storeData = (userDetails) => {
let userName = userDetails.userName;
let storeSuccess = firestore()
.collection('Users')
.doc('123')
.set({
username: userDetails.userName,
userselfie: userDetails.userSelfie,
LP: userDetails.LPImage,
bill: userDetails.BillImage,
customercontact: userDetails.customerContact,
date: userDetails.date,
time: userDetails.time,
})
.then(() => console.log('success'))
.catch((error) => {
error.message && alert(error.message);
console.log(
'Something went wrong while adding user data to firestore: ',
error,
);
return 'error';
});
return storeSuccess;
};
推荐阅读
- python - Pyarrow:TypeError:需要一个整数(获取类型 str)
- powershell - 如何使用 powershell 为新用户设置默认打印机
- javascript - 更改文本框的值不起作用
- c++ - 一个变量的输入值也被保存到另一个变量中
- wpf - 为网格中的一行添加 IsEnabled (WPF)
- object - 接口如何在较低/装配级别表示?
- javascript - 如何在页面加载时使用角度“ng”标签调用函数?
- mulesoft - Mulesoft - 捕获 http 状态
- python - 全新安装后无法运行apache气流,python导入错误
- apache-beam - 在 Google Colab 上安装 beam 时如何修复错误