[英][Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'response.data')]
[英][Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_ref.about')]
首先,不要评判我,我对整个 React Native 场景和 Javascript 场景都很陌生,学习主要是为了我在学校的最后一个顶点。
在图片中,您将看到我的数据库,我正在尝试使用 async 进行操作,但遇到了问题。
我的目标
能够添加并最终编辑/更新用户信息以通过前端显示在个人资料页面和设置页面上。
到目前为止发生了什么
我能够通过后端工作让它工作。 这意味着我正在物理上进入我的数据库并以这种方式添加和更改它,但这不是我想要发生的事情。 我希望我的用户拥有完全控制权。
我的“设置”页面中的“关于我”部分
<Block row space="between" margin={[10, 0]} style={styles.inputRow}>
<Block>
<Text gray2 style={{ marginBottom: 10 }}>
Bio
</Text>
{this.renderEdit("about")}
</Block>
<Text
medium
secondary
onPress={() => this.toggleEdit("about")}
>
{editing === "about" ? "Save" : "Edit"}
</Text>
<Button
onPress={() => {
Fire.shared.addInfo();
}}
title="Add"
/>
</Block>
到目前为止,这不是错误而只是警告,我确定我缺少更多代码以使其正常工作
我的 fire.js 页面的添加信息部分
addInfo = async({ about }) => {
return new Promise ((res, rej) => {
this.firestore
.collection("users")
.add ({
about,
})
.then(ref => {
res(ref);
})
.catch(error => {
rej(error);
});
});
};
我在这里做错了什么。 如果有人可以提供帮助,我会很失落,那就太好了
你在这里犯了几个错误:
asyncawait
库而不是内置库我想你想要实现的目标可以是这样的:
class YourFireClass {
...
addInfo(userInfo) {
return this.firestore.collection("users").add(userInfo);
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.