【发布时间】:2021-03-25 10:01:42
【问题描述】:
Firebase 设置功能不适用于嵌套字典
const [appInitialized, setAppInitialized] = useState(false)
// Where FireBase is name of function that initializes firebase
FireBase().then(() => {
setAppInitialized(true)
})
const [user, loading, error] = useAuthState(firebase.auth());
useEffect(() => {
if (appInitialized) {
SingingInAnonymously()
}
}, [appInitialized, loading])
function SingingInAnonymously() {
if (!loading) {
if (!user && !loading) {
firebase.auth().signInAnonymously()
.then((response) => {
const reference = "Users/" + response.user.uid
console.log("RUNNING TO ADD USER", reference)
firebase.database().ref(reference).set(
{
CurrentAvatar: "https://firebasestorage.googleapis.com/v0/b/just-an-app-96ed6.appspot.com/o/Avatars%2FRad.png?alt=media&token=dae7e13b-ac3a-4fd9-a5e5-8342e84dc13e",
UnlockedAvatars: ["PushID1"]
}
).then((e) => console.log("success")).catch((e)=>console.log(e))
setAppInitialized(false)
}).catch((e) => {
})
}
}
}
我也试过
UnlockedAvatars: { "0" : "PushID1" }
如果我将“set”更改为“push”,它会起作用,否则它不起作用,不会给出任何错误,也不会进入 then 语句。
如果我删除嵌套字典 UnlockedAvatars: ["PushID1"] / UnlockedAvatars: {"0": "PushID1"} 它可以工作
如果我更改对常量字符串的引用,它仍然有效
【问题讨论】:
标签: javascript reactjs firebase