我如何将数据从 firestore 传递到 react-native 中的函数

how can i pass data from firestore to a function in react-native

这是我要将数据传递给的函数

 function db(threads) {
    setThreads(threads);
    if (initializing) setInitializing(false);
  }

这是我查询的数据

useEffect(() => {
  firestore().collection('User').onSnapshot(querySnapshot => {
    const list = [];
    querySnapshot.forEach(doc => {
      const {  id, name  } = doc.data();
      list.push({
        _id: doc.id,
        id,
        name,
        // add this
        latestMessage: {
          text: '',
          userName: '',
          avatar: '',
        },
      });
    });
    db(list); });
}, []);

请帮帮我,我已经研究了一段时间了。

我使用的是最新版本的 react-native 和 firebase。

它一直显示这个错误

TypeError: null is not an object (evaluating '_useContext7.threads')

但是当我将它们记录到控制台时,我可以在那里看到数据库中的所有数据。

我只需要 threads.id 和 threads._id

再见,试着像这样修改你的useEffect

useEffect(() => {
firestore().collection('User').onSnapshot(querySnapshot => {
const list = [];
querySnapshot.data().forEach(doc => {
  list.push({
    _id: doc.id,
    id: doc.id,
    name: doc.name,
    // add this
    latestMessage: {
      text: '',
      userName: '',
      avatar: '',
    },
  });
});
db(list); });
}, []);