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

317
Views
Why I encountered is not iterable?

I have this error and I started to learn React last week so I couldn't solve the problem.

Uncaught TypeError: contacts is not iterable
    at onSubmit (index.js:15:1)

Contacts Component

import List from "./List"
import Form from "./Form"
import {useState,useEffect} from "react"
import React  from "react"

function Contacts(){

    const [contacts,setContacts] = useState([]);

    useEffect(()=>{
        console.log(contacts)
    },[contacts])   

    return (
        <div>
            <List/>
            <Form addContact = {setContacts} contacts={contacts}/>
        </div>
    )
}


export default Contacts

Form Component

import React from "react"
import { useState } from "react"

function Form(addContact,contacts){
    
    const [form,setForm] = useState({fullName : "" , phoneNumber : ""})

    const onChangeInput = (event) => { setForm({...form,[event.target.name]: event.target.value}) }

    const onSubmit = (event) => {
        event.preventDefault();
        if(form.name ==="" || form.phoneNumber===""){
            return false
        }
        addContact([...contacts , form]);
    }

    return (
        <form onSubmit={onSubmit}>
            Form List
            <div><input name="fullName" placeholder="fullName" onChange={onChangeInput}></input></div>
            <div><input name="phoneNumber" placeholder="phoneNumber" onChange={onChangeInput}></input></div>
            
            <div>
                <button>Add</button>
            </div>
        </form>
    )
}


export default Form
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

please use props like this wrap with {}

function Form({ addContact, contacts }){
...
...
...
}
about 4 years ago · Santiago Gelvez 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!