I'm creating an object with firebase to display it in the screen, but after the creation I will need its id in another page to show the object with more details (path example: /object/:id), so when I click the object, I need to take its id and send through the link to another page, and once I'm in the page I will query the id on the link to get the object like that:
query(collection(db, "objects"), where("objectId", "==", x))
and this is how im creating the object
<form onSubmit={(e) => {
e.preventDefault()
// checks if user is logged in
onAuthStateChanged(auth, (user) => {
if(user) {
addDoc(collection(db, "objects"), {
name: "my object",
description: "a nice object",
owner: user.uid,
// objectId: x
}).then((docRef) => {
docRef.id // I need this to be in the objectId property
})
}})
}}>
I would like to know if this is a good approach to this problem, since I will need this id later on the project I thought this was the best way to do it