"Unhandled Rejection (TypeError): snapshot.data is not a function" when calling Firestore in useEffect

I have a React component rendering cafe’ and ‘cafe review’ data. I’m making two API calls – one to my cafes collection, the the other to my reviews collection, and I’ve put them both inside a useEffect hook, as follows:

    const [cafe,setCafe] = useState({name:'',photoURL:'',address:'',phoneNumber:'', website:''})
    const [reviews,setReviews] = useState({blurb:'', cafeName:'',stars:'',title:'',userName:''})
    let id = match.params.id

 useEffect(() => {
        .then(snapshot => {
              name: snapshot.data().name,
              photoURL: snapshot.data().photoURL,
              address: snapshot.data().address,
              phoneNumber: snapshot.data().phoneNumber,
              website: snapshot.data().website

        .then(snapshot => {
            console.log(snapshot.data())  //*this* yeilds the error

The call to the cafes collection is working successfully, and is returning all the data. However the second call to the reviews collection is failing. When I log snapshot.data() to the browser I get the following error:

Unhandled Rejection (TypeError): snapshot.data is not a function

This is strange because performing the equivalent log on the cafes api call successfully shows the object in the browser.

I tried adding some conditional code, which failed to yield any data:

        .then(doc => {
            if(doc && doc.exists){
            } else {
                console.log('no doc')

Any suggestions on how I can get both API calls to return data? Am I using useEffect wrong here?

224 thoughts on “"Unhandled Rejection (TypeError): snapshot.data is not a function" when calling Firestore in useEffect”

  1. Pingback: viagra buy
  2. Pingback: liquid cialis
  3. Pingback: viagra canada
  4. Pingback: viagra sample
  5. Pingback: buy cialis cheap
  6. Pingback: ivermectin amazon
  7. Pingback: cialis 20
  8. Undeniably believe that which you said. Your favorite justification appeared to be on the net the
    easiest thing to be aware of. I say to you, I certainly get annoyed
    while people consider worries that they just don’t know about.
    You managed to hit the nail upon the top and also
    defined out the whole thing without having side-effects , people could
    take a signal. Will likely be back to get more.

    Thanks http://ciaalis2u.com/

  9. Pingback: sildenafil
  10. Pingback: viagra pfizer
  11. Pingback: viagra cost
  12. Pingback: viagras
  13. Pingback: cialis viagra
  14. Pingback: walgreens viagra
  15. Pingback: viagra for women
  16. Pingback: cheap viagra
  17. Pingback: sildenafil tablets
  18. Pingback: roman sildenafil
  19. Pingback: cialis mexico

Leave a Comment