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

135
Views
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 answers
Answer question

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 Report

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 Report
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!