Skip to content
Advertisement

How to return data from Firestore query to a FlatList

I’m new to React-Native and I am trying to return the array of data from the firstore query to the device screen where I can setDevices. I had this working using .get() and .then(), but I wasn’t getting the updated events, so I’ve moved to onSnapshot and seem to have data at the query end, but can’t get this set at the screen.

JavaScript

This error appears. If I remove .then(setDevices) I can see the array of data on the console.log

JavaScript

Thanks

Advertisement

Answer

There are several problems in your code.

  1. You don’t return the Promises chain.
  2. id is not defined. You need to do doc.id.

So the following should do the trick:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement