React Native Firebase数据仅在调试器模式下显示

时间:2020-04-04 03:33:38

标签: javascript reactjs react-native react-native-firebase

当我在debugger mode时,这是我的屏幕外观:

enter image description here

当我不在debugger mode时,我的屏幕如下所示:

enter image description here

App.js

import React, {useEffect, useState} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {getThoughts} from './src/util/functions';
import firebase from './src/util/firebase';

const App = () => {
  const [thoughts, setThoughts] = useState([]);
  // Fetch api data
  useEffect(() => {
    const fetchData = async () => {
      const db = firebase.firestore();
      const data = await db.collection('thoughts').get();
      setThoughts(
        data.docs.map((doc) => {
          return doc.data();
        }),
      );
    };

    fetchData().catch((error) => error);
  }, []);

  return (
    <View style={styles.container}>
      <View style={styles.content}>
        {thoughts.length > -1 ? (
          thoughts.map((val) => {
            return (
              <Text style={styles.text} key={val.thought}>
                {val.thought}
              </Text>
            );
          })
        ) : (
          <Text style={styles.text}>Loading...</Text>
        )}
      </View>
    </View>
  );
};

我已经有大约一天的时间了。我非常感谢您提供任何帮助,解释我为什么遇到这个问题以及如何解决这个问题。

0 个答案:

没有答案
相关问题