【问题标题】:(FirebaseError): Function DocumentReference.set() called with invalid data in reactjs(FirebaseError):函数 DocumentReference.set() 在 reactjs 中使用无效数据调用
【发布时间】:2021-08-29 12:50:31
【问题描述】:

在代码下方运行时遇到此 firebase 异常,当我尝试将数据添加到 firebase 数据库时,我在 react 应用程序中遇到了这个问题。

例外: 未处理的拒绝 (FirebaseError):使用无效数据调用函数 DocumentReference.set()。不支持的字段值:未定义(在文档 users/zk97w62poVh62epn4atnXncOSKd2/orders/pi_1J1o7XSAf8PnDB2r8kkLLunf 中找到)

任何人都可以在这里帮助我! 有关控制台日志,请参阅下图。

enter image description here

'''

const handleSubmit = async(e) => {
        e.preventDefault();
        setProcessing(true);

        const payload = await stripe.confirmCardPayment(clientSecret, {
            payment_method: {
                card : element.getElement(CardElement)
            }
        }).then(({paymentIntent}) => {   
            console.log(basket)
        console.log(paymentIntent.amount)
        console.log(paymentIntent.created)

        const data = {
            basket: basket,
            amount: paymentIntent.amount,
            created: paymentIntent.created
        }

        console.log(typeof(data))

        console.log(data)
       
        db
          .collection("users")
          .doc(user?.uid)
          .collection("orders")
          .doc(paymentIntent.id)
          .set(data)
            } ))


            setSucceeded(true)
            setError(null)
            setProcessing(false)

            dispatch({
                type : "EMPTY_BASKET"
            })

            history.replace("/orders")

        })
    }
'''

【问题讨论】:

  • 嘿苏雷什。你在这方面有什么进展吗?我试图在下面提供答案。您看到并尝试一下了吗?

标签: javascript reactjs firebase google-cloud-firestore


【解决方案1】:

从错误消息中,您的data 对象中的值看起来像是undefined。从屏幕截图看来,这很可能是在basket。我建议使用console.log(JSON.stringify(basket)) 进行故障排除。

【讨论】:

  • 是的,整理好了。就像你说的,问题出在数据对象上。其中一个数据键未定义,这就是引发此问题的原因。
猜你喜欢
  • 2020-04-18
  • 2022-07-20
  • 2021-02-26
  • 2019-12-07
  • 2020-04-24
  • 2023-03-24
  • 1970-01-01
  • 2020-08-20
相关资源
最近更新 更多