【问题标题】:Uncaught TypeError: Cannot destructure property 'getFirestore' of 'undefined' as it is undefined未捕获的类型错误:无法解构“未定义”的属性“getFirestore”,因为它未定义
【发布时间】:2020-11-13 21:56:43
【问题描述】:

我对 react firebase/firestore 有这个问题

错误:

未捕获的类型错误:无法解构“未定义”的属性“getFirestore”,因为它是未定义的

export const createTask = (task) => {
    return(dispatch, getState, {getFirestore}) => {
        const firestore = getFirestore();

        firestore.collection('task').add({
            ...task,
            author: 'Steven',
            authorId: 1223,
            createdAt: new Date()
        }).then(() => {
            dispatch({type: CREATE_TASK, task })
        }).catch((err)=>{
            dispatch({type: CREATE_TASK_ERROR, err})
        })

    }
}

有人知道要找什么吗?

【问题讨论】:

  • const firestore = getFirestore;

标签: reactjs firebase


【解决方案1】:

我认为您的问题不在于您共享的代码,而在于您使用它的方式。

这应该可以工作:

const myTask=createTask(aTask);
myTask(dispatch, getState, {getFirestore});

【讨论】:

    猜你喜欢
    • 2022-07-20
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2022-01-08
    • 2017-07-26
    相关资源
    最近更新 更多