Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

550
Vistas
How to read array document field from firebase firestore (React js)

Hi I am trying to get todo array field from cloud firestore database in a react project. When i print out with console log I can see the empty array symbol but It throws error at the same time and does not render the page.

enter image description here

This is the Firestore.js file to get data from firebase.

export const userTodoList = async (email) => {
  await onSnapshot(doc(db, "users", email), (doc) => {
    console.log(doc.data().todos);
    return doc.data().todos;
  });
};

This the MainPage.js file to get the array and pass to CardList component.

 const MainPage = () => {
      const todoArray = userTodoList(auth.currentUser.email);
      const [todos, setTodos] = useState(todoArray);
      return (
        <div>
          <section>
            <NavBar></NavBar>
            <ToDoForm />
          </section>
          <section>
            <CardList array={todos} />
          </section>
        </div>
      );
    };

This is the CardList component to render the cards with the array mapping. I am checking for if the array length is 0 or not but still get errors.

const CardList = (props) => {
  const array = props.array;
  if (array.length === 0) {
    return (
      <div className="grid_container">
        <h2>Found no todos</h2>
      </div>
    );
  }
  return (
    <div className="grid_container">
      {array.map((todo) => (
        <Card title={todo.title} />
      ))}
    </div>
  );
};

Errors.

enter image description here enter image description here

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda