Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
How can I load in firestore documents into a flatlist?

I'm trying to simply load documents from a Firestore db into a Flatlist in react-native. I'm using expo to monitor changes to my application. I've been running into a few errors that I can't seem to get around,any help would be appreciated! I'm new to using react-native & Firebase.

import {
  StyleSheet,
  Alert,
  SectionList,
  SafeAreaView,
  Image,
  FlatList,
  TextInput,
  ActivityIndicator,
} from "react-native";
import React, {
  useState,
  useEffect
} from "react";
import EditScreenInfo from "../components/EditScreenInfo";
import {
  Text,
  View
} from "../components/Themed";
import {
  StatusBar
} from "expo-status-bar";
import {
  List
} from "react-native-paper";

import {
  initializeApp
} from "firebase/app";
import {
  getFirestore,
  collection,
  getDoc,
  addDoc,
  doc,
  setDoc,
} from "firebase/firestore";

const firebaseConfig = {
 ...
};

export default function TabTwoScreen() {
  const [loading, setLoading] = useState(true); //Set loading to true on component mount
  const [users, setUsers] = useState([]); //initial empty array of users

  // Initialize Firebase
  const db = getFirestore(app);
  const firestore = getFirestore();
  const app = initializeApp(firebaseConfig);

  //this hook triggers when components mount, then subscribe to collection
  useEffect(() => {
    const subscriber = firestore()
      .collection(db, "Users")
      .onSnapshot((querySnapshot) => {
        const users = [];

        querySnapshot.forEach((documentSnapshot) => {
          users.push({
            ...documentSnapshot.data(),
            key: documentSnapshot.id,
          });
        });

        setUsers(users);
        setLoading(false);
      });

    // Unsubscribe from events when no longer in use
    return () => subscriber();
  }, []);

  if (loading) {
    return <ActivityIndicator / > ;
  }

  return (
   <FlatList
   data={users}
   renderItem={({ item }) => (
    <View>
      <Text>User ID: {item.id}</Text>
      <Text>User Name: {item.name}</Text>
    </View>
  )}
/>
  );
}

the errors I keep receiving are

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). This error is located at: in TabTwoScreen (created by SceneView)

Invariant Violation: "main" has not been registered. This can happen if: Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.

  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called.**
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!