如何修复此错误“ Function CollectionReference.doc()”

时间:2019-05-09 12:09:29

标签: firebase react-native

我正在创建一个小型的本机应用程序,当我添加一些代码以从Firebase中删除数据时,它向我显示此错误:“ FirebaseError:Function CollectionReference.doc()要求其第一个参数的类型为非空字符串,但这是:未定义”

**这是我的动作:

import firebase from 'firebase/app'

const deleteChat = (id) => {
    return (dispatch, getState, getFirestore) => {
        if (id !== null) {
            firebase.firestore().collection('chat').doc(id).delete()
                .then(() => {
                    dispatch({
                        type: "DELETE_CHAT",
                        id
                    })
                })
        }

    }
}

1 个答案:

答案 0 :(得分:0)

您仅在检查id是否为null。您的情况id是不确定的。

您可以通过以下方式解决此问题: if (id !== null && id !== undefined) 甚至更好或更短(它会同时检查null和undefined)

if (id) {
 ...
}