Arshia
Arshia

Reputation: 35

Firebase Error: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: a custom Q object

I am trying to use hooks in order to update the state of a list of data. I am using react native. I dont even know what custom Q object is. :/

function userStoresList() {
  const [userStores, userStoresUpdate] = useState([]);
  const uid = firebase.auth().currentUser;
  useEffect(() => {
    firebase
      .firestore()
      .collection('users')
      .doc(uid)
      .collection('stampcards')
      .onSnapshot(snapshot => {
        const newUserStores = snapshot.docs.map(doc => ({
          id: doc.id,
          ...doc.id(),
        }));
        userStoresUpdate(newUserStores);
      });
  }, []);
  return userStores;
}

function UserStampScreen() {
  console.log('Initial Render (step 1)');
  const userStores = userStoresList();



{userStores.map(store => (
              <StampCards
                key={store.id}
                name={store.name}
                promotion={store.promotion}
                stamps="5/10 Stamps"
                image={store.image}
              />
            ))}

I am trying to understand why it is outputting this error: Error

If you guys need more information, just ask. np

Upvotes: 0

Views: 2670

Answers (1)

Thingamajig
Thingamajig

Reputation: 4465

firebase.auth().currentUser does not return just the uid, but rather an object that contains the uid.

You can just change:

const uid = firebase.auth().currentUser

to

const { uid } = firebase.auth().currentUser

Upvotes: 1

Related Questions