Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
React Native with Firebase v9

i am new to react native ,i am trying to fetch the data from my firebase database. i am trying to list out name and age from my firestore collection,

here is my code:

const HomeNurse=({ navigation }) => {

    const [users, setUsers] = useState([]);
    const [currentPage, setCurrentPage] = useState(1);
    const [isLoading, setIsLoading] = useState(false);
  
    const getUsers = async () => {
      let result = [];
      
      const querySnapshot = await getDocs(collection(db, "MyCollection"));
      querySnapshot.forEach((doc) => {
        console.log(doc.id, "=>" , doc.data());
        result.push(doc.data());
      });
  
      setUsers([...result]);
    };
  
    useEffect(() => {
      getUsers();
    }, []);
  
    const renderItem = ({ item }) => {
      return (
        <View>
          <View>
            <Text>{`${item.name}`}</Text>
            <Text>{`${item.age}`}</Text>
          </View>
        </View>
      );
    };
  
    const renderLoader = () => {
      return isLoading ? (
        <View style={styles.loaderStyle}>
          <ActivityIndicator size="large" color="#aaa" />
        </View>
      ) : null;
    };
  
    const loadMoreItem = () => {
      setCurrentPage(currentPage + 1);
    };
  
    return (
      <View>
        <StatusBar backgroundColor="#000" />
        <FlatList
          data={users}
          renderItem={renderItem}
          keyExtractor={(item) => item.id}
          ListFooterComponent={renderLoader}
          onEndReached={loadMoreItem}
          onEndReachedThreshold={0} />
      </View>
    );
  };
  
 

the output is just a blank screen with a warning:

Possible Unhandled promise rejection id:0

at the terminal:

[Unhandled promise rejection: TypeError: (0, _firebase.collection) is not a function. (In '(0, _firebase.collection)(_firebase.db, "MyCollection")', '(0, _firebase.collection)' is undefined)]

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda