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

267
Vistas
Argument of type 'void' is not assignable to parameter of type 'SetStateAction<never[]>'.ts(2345)

I want to implement a code to retrieve data from firestore collection

I use typescript as a programming language. But found an error while following the existing example, while the example uses javascript

the error occured at setBookmark(querySnapshot.forEach((doc) => {

React.useEffect(() => {
    const getBookmark = async () => {
      try {
        const querySnapshot = await getDocs(collection(db, "bookmark"));
        setBookmark(querySnapshot.forEach((doc) => {
          id: doc.id,
          data: doc.data()
          // console.log(`${doc.id} => ${doc.data()}`);
        }));
      } catch (e) {
        console.error("Error getting document: ", e);
      }
    };

    getBookmark();
  }, []);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

forEach returns void hence the error. I think you want to use .map instead. Your current would always set setBookmark(null). I would write the code for you but its not clear what goes into bookmark.

map will return a new list based on the old list while forEach is to just iterate and not returning anything.

about 4 years ago · Juan Pablo Isaza Denunciar

0

As I remember, you can't use map with querySnapshot, but you can create an array from it.

const myArray = [];
querySnapshot.forEach((doc) => {
  myArray.push({
    id: doc.id,
    data: doc.data()
  })
setBookmark(myArray)
about 4 years ago · Juan Pablo Isaza Denunciar
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