【发布时间】:2021-05-19 20:55:32
【问题描述】:
当我尝试使用 firebase 更新我的用户个人资料时遇到问题。如果按“保存”所有内容都会保存在数据库中,但是当应用程序尝试导航回配置文件时会崩溃。如果我重新加载应用程序,我可以看到我保存的输入显示,所以当我尝试导航时出现问题。
我得到的错误信息是:
undefined 不是一个对象(评估 'props.route.params.uid")
通过使用以下代码:
const Save = async () => {
if (imageChanged) {
const uri = image;
const childPath = `profile/${firebase.auth().currentUser.uid}`;
const response = await fetch(uri);
const blob = await response.blob();
const task = firebase
.storage()
.ref()
.child(childPath)
.put(blob);
const taskProgress = snapshot => {
console.log(`transferred: ${snapshot.bytesTransferred}`)
}
//Saving the Image
const taskCompleted = () => {
task.snapshot.ref.getDownloadURL().then((snapshot) => {
firebase.firestore().collection("users")
.doc(firebase.auth().currentUser.uid)
.update({
description,
image: snapshot,
})
.then(() => {
props.navigation.goBack()
})
})
}
const taskError = snapshot => {
console.log(snapshot)
}
task.on("state_changed", taskProgress, taskError, taskCompleted);
//Save the data if you just save description
} else {
saveData({
description,
})
}
}
//Save data navigate back to the profile.
const saveData = (data) => {
firebase.firestore().collection("users")
.doc(firebase.auth().currentUser.uid)
.update(data).then(() => {
props.navigation.push("BackToProfile")
})
}
所以如果我像这样添加我的 currentUser UID,我会收到以下消息:
“Function CollectionReference.doc() 要求它的第一个参数是非空字符串,但是是:未定义”
//Save data navigate back to the profile.
const saveData = (data) => {
firebase.firestore().collection("users")
.doc(firebase.auth().currentUser.uid)
.update(data).then(() => {
props.navigation.push("BackToProfile", {uid: currentUser.uid})
})
}
我从 Redux 获得的 CurrentUser。我像这样使用 currentUser 显示图像,它工作正常。所以我想如果想要 UID 我应该做同样的事情,还是我想错了?
profileImage={currentUser.image}
当导航完成时。想要我更新我的个人资料图片 和说明。但现在我必须重新加载应用程序。
【问题讨论】:
-
你能粘贴整个实现吗?
-
感谢您的回答,我添加了整个实现。
标签: firebase react-native redux