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

277
Views
Agregue un objeto único en la matriz reactjs

tengo un problema aquí, cuando hago clic en un elemento 2 veces, agregará 2 veces a mi matriz, no sé cómo agregar un elemento único a la matriz, ¿pueden ayudarme? Gracias chicos

 const handleClick = ( id: number, name: string | null, avatar: string | null ) => { setListChoose((prevState: any) => [...prevState].concat({ id, name, avatar }) ); };

ingrese la descripción de la imagen aquí

over 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede verificar si ese contacto existe en la matriz o no. Si no es así, añádalo en la lista; de lo contrario, no lo haga.

 const handleClick = ( id: number, name: string | null, avatar: string | null ) => { let list = Array.from(listChoose); //assuming that list name is listChoose. if(list.find(l => l.id === id) === undefined){ setListChoose((prevState: any) => [...prevState].concat({ id, name, avatar }) ); } };
over 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
Virtual assistant