0

I am currently having this problem but I cannot seem to figure out the solution:

I have this function:

// initialize
const [title, setTitle] = useState('');
const [isRecyclable, setIsRecyclable] = useState('');

// function
  const handleSubmitData = (e) => {
    e.preventDefault();
    fetch('https://recycling-barcode-api.herokuapp.com/database%27)
      .then(response => response.json())
      .then((responseJson) => {
        console.log(responseJson);
        responseJson.forEach((item) => {
          if (title === item['title']) {
            setIsRecyclable(item['isRecyclable']);
          } else {
            setIsRecyclable('Item not found')
          }
        })
      })
      .catch(err => console.error(err));
  }

// database
{
    "database": [
        {
            "title": "Coca-Cola Life Soda Soft Drink, 7.5 Fl Oz, 6 Pack",
            "isRecyclable": true
        },
        {
            "title": "Coca-Cola Rare Napkin Tray with Bottle Handle with Coca-Cola Napkins",
            "isRecyclable": true
        },
        {
            "title": "Samsung 970 EVO Plus 1TB SSD (MZ-V7S1T0B/AM)",
            "isRecyclable": false
        },
        {
            "title": "Macbook Pro",
            "isRecyclable": false
        },
        {
            "title": "Kids Water Bottles Bulk, Portable Travel Bottle Water Cup Leak-proof Plastic Sports Straw Cup Bottle, Material Plastic",
            "isRecyclable": true
        }
    ]
}

---> so the object returns as an array and I want to loop through the array to see if the title matches with the title in the database. But it gives me this error:

TypeError: Converting circular structure to JSON
Uncaught (in promise) TypeError: this.activeCallback is not a function

----Do you know why? Please help! thank you

  • Does this answer your question? [Chrome sendrequest error: TypeError: Converting circular structure to JSON](https://stackoverflow.com/questions/4816099/chrome-sendrequest-error-typeerror-converting-circular-structure-to-json) – Youssouf Oumar Aug 13 '22 at 09:47
  • I am not too sure, because in console, it did show the return array. There is something wrong in the if statement but idk what it is – Nam Tran Aug 13 '22 at 09:52

0 Answers0