【发布时间】:2022-01-23 11:59:11
【问题描述】:
问题
- 我在使用 react-redux-thunk 向 firebase 数据库添加数据时遇到问题
- 我检查了文档并观看了多个 youtube 视频,但在出错后一直出错
- 我想分别使用“redux-firestore”和“react-redux-firebase”库中的
getFirestore和getFirebase中间件将数据添加到firebase 文档
代码
- 这里是动作函数
- 所有代码似乎都在工作,但我不知道如何将
validatonResults添加到users/uid(请参阅下面代码中的注释) - 尝试了以下代码(以及许多其他内容),但没有成功
firebase.push('users', { data: validatonResults })
import inputValidationAPI from "../../apis/inputValidationAPI"
export const validateTestCase = payload => {
return (dispatch, getState, { getFirebase, getFirestore }) => {
const fireStore = getFirestore()
const firebase = getFirebase()
const uid = getState().firebase.auth.uid
inputValidationAPI
.post("/submitTerm", {
term: payload
})
.then(response => {
return response.data.data
})
.then(validatonResults => {
/*
validationResults = ["string1", "string2", "string3"]
I want to take validationResults and add them into firebase collection something like:
firebase.push('todos/${uid}', { some: 'data' })
*/
return validatonResults
})
.then(validatonResults => {
dispatch({
type: "VALIDATE_TESTCASE_SUCCESS",
payload: validatonResults
})
})
.catch(err => console.log(err))
}
}
【问题讨论】:
-
在向 firebase 数据库添加数据时,您遇到了什么问题?你能在这里显示你的错误吗?
-
想通了,关闭这个问题
-
@OG_On_The_Beat 你发现了什么?你能把它作为答案发布吗?当有人遇到同样的问题时,它会帮助社区。span>
标签: javascript firebase google-cloud-firestore redux react-redux-firebase