Business
Jobs
  • About Us
  • Solutions
    • Candidates
      Highly qualified candidates in 48h.
    • Assessments
      500+ technical and psychological assessments, plus anti-fraud system.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Pay in 15+ LATAM countries without setting up a local entity.
  • Pricing
  • Jobs

0

428
Views
Estado de actualización | el objeto no es iterable (no se puede leer la propiedad Symbol(Symbol.iterator))

Tengo debajo de JSX -

 <FormGroup> <Label for="exampleEmail" style={{fontWeight:"bold"}}>What is your e-mail address?</Label> <Input type="email" name="email" id="exampleEmail" onChange={(e)=>setStateForProperties(e)} /> </FormGroup> <FormGroup> <Label for="examplePassword" style={{fontWeight:"bold"}}>What is your password?</Label> <Input type="password" name="password" id="examplePassword" onChange={(e)=>setStateForProperties(e)}/> </FormGroup>

Declaraciones Estatales -

 const iLoginCreds ={ userName:'', password:'' } const [loginCreds, setLoginCredentials] = useState(iLoginCreds)

onChange Cambio de estado del método -

 function setStateForProperties(e) { alert(e.target.id); switch (e.target.id) { case 'exampleEmail': setLoginCredentials(...loginCreds,{ userName:e.target.value }); break; case 'examplePassword': setLoginCredentials(... loginCreds,{ password:e.target.value }); default: break; } console.log(loginCreds); }

Error -

Cuando escribo algo en el cuadro de texto (al activar el evento onchange), recibo un error:

 TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))

ingrese la descripción de la imagen aquí

almost 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe destruct las previous object properties y devolver un new object después de fusionarse con el nuevo.

 setLoginCredentials({ ...loginCreds, ...{userName:e.target.value} })
almost 4 years ago · Juan Pablo Isaza Report

0

En lugar de hacer esto:

 setLoginCredentials(...loginCreds, { userName:e.target.value });

, que pasa 2 argumentos a useState , debe mover las llaves para rodear ...loginCreds , así:

 setLoginCredentials({...loginCreds, userName:e.target.value });

Deberías hacer lo mismo con la contraseña.

Esto cambiará solo una propiedad en el objeto. Reaccionar Ganchos useState() con Objeto

almost 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!