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

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
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