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

137
Vistas
array state not iterable

PS- This post is the prime example on how we forget the basic things ...man i am sure feeling dumb XD

I am new Here so stack overflow dosnt let me embed the pics..

I am creating an Ebook management system where i wanted to make favorite book list when i click "add to fav" button on every book

this function is called when i press the "add to fav" button where favList is an empty array state

 const [favList, setfavList] = useState([]);

//BookList is an array of books which are fetched from google books API

const addFav = () => {
    return setfavList(
      ...favList,
      BookList.find((t) => id == t.id)
    );
  };

But whenever i click multiple books an error occurs The Error

Here is the declaration of my states State Declaration

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Are you using hooks, show the code where you declaring the favlist

Try this:

const addFav = () => {
if(favList.length)
return setfavList(
  ...favList,
  BookList.find((t) => id == t.id)
);
 else 
    return setfavList(
      BookList.find((t) => id == t.id)
    );
  };
about 4 years ago · Juan Pablo Isaza Denunciar

0

Never mind i found what i had to do

const addFav = () => {
    return setfavList([
      ...favList,
      BookList.find((t) => id == t.id)]
    );
  };

we all were just missing the square braces yeah kinda lame but thanks for all the help

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