I try to add a user in Firestore with a custom ID.
import { db } from "../firebase/config";
import {collection, addDoc, deleteDoc, updateDoc, doc, setDoc} from 'firebase/firestore'
export const useFirestore = (collections) => {
const addDocumentUser = async (doc, id) => {
try{
const addedDocument = await setDoc(doc(db, collections, id), {...doc});
return addedDocument.id
}
catch(err){
console.log(err)
dispatch({type: 'ERROR', payload: err})
}
}
return {addDocumentUser}
}
When I run it I receive following error in the consol:
TypeError: doc is not a function
at addDocumentUser (useFirestore.js:62:1)
at useSignup.js:29:1
at async signup (useSignup.js:23:1)
at async handleSubmit (Signup.js:23:1)
What I am doing wrong? I imported everything and the database access works for functions (addDoc) without the custom id.
CodePudding user response:
The problem is that you're redefining doc
, so it has two definitions:
import { db } from "../firebase/config";
import {collection, addDoc, deleteDoc, updateDoc, doc, setDoc} from 'firebase/firestore'
//