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

71
Views
Agregar una clase y establecer estados dentro de la misma función en React

Tengo una función en React en la que intento cambiar el estado y agregar una clase que diseñe el botón en el que se hizo clic. El problema es que cuando evito alterar el estado en la función userAnswers() , el estilo funciona, pero cuando agrego setChoices() , el estilo no funciona. Este es el código:

 function userAnswers (e) { const choiceBtns = document.querySelectorAll(".choice-btns") choiceBtns.forEach((btn) => { if (e.target.id === btn.id) { btn.classList.remove("chosen") } }) e.target.classList.add("chosen") setChoices((prev) => { return prev.map((q) => { return {...q, [e.target.value]: false} }) }) setChoices((prev) => { return prev.map((q) => { if (q.id === e.target.id) { return {...q, [e.target.value]: true} } else { return {...q} } }) }) }

¡No sé, me estoy perdiendo algo aquí! Cualquier ayuda sería apreciada.

about 4 years ago · Juan Pablo Isaza
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!