You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When i try to debug and console.log (listings) or console.log(car)
I dont get id for each item, except id i can get every field that is in my collection.
I think {idField:'id:} is not grabbing id from the collection
As a side note I am using firebase 9, installed react-firebase-hooks @latest , created
Vite react project @latest
simple example:
importReactfrom"react";import{useGlobalContext}from"../../../Context/Context";import{db}from"../../../FirebaseConfig/firebaseConfig";import{collection,query,where}from"firebase/firestore";import{useCollectionData}from'react-firebase-hooks/firestore';importCarListingfrom"./CarListing";constListings=()=>{const{ user }=useGlobalContext();constcarsRef=collection(db,"cars");constq=query(carsRef,where("addedByUID","==",user?.uid));const[listings,loading,error]=useCollectionData(q,{idField: 'id'});if(loading){return<divclassName="loading"></div>;}if(error){console.error("Error fetching user listings: ",error);return<div>Error fetching data</div>;}return(<divclassName="listing-car-container">{listings&&listings.length>0 ? (listings.map((car)=><CarListingkey={car.id}car={car}/>)) : (<p>You haven't listed any cars yet.</p>)}</div>);};exportdefaultListings;
The text was updated successfully, but these errors were encountered:
You can append the id to your documents with the FirestoreDataConverter. You will receive the id in the fromFirestore function with the snapshot.id value. An example how to do this is in the documentation under transforming-data
When i try to debug and console.log (listings) or console.log(car)
I dont get id for each item, except id i can get every field that is in my collection.
I think {idField:'id:} is not grabbing id from the collection
As a side note I am using firebase 9, installed react-firebase-hooks @latest , created
Vite react project @latest
simple example:
The text was updated successfully, but these errors were encountered: