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

212
Views
¿Por qué la clase no se procesa después del estado establecido en reaccionar js?

Quiero agregar una clase activa al indicador después de hacer clic en él, pero la clase activa no aparece aunque list.id === active

 const [active, setActive] = useState(1); const scrollToElement = (id, value) => { const element = document.getElementById(`${value}`); element.scrollIntoView({ behavior: 'smooth' }); setActive(prevState => { return { ...prevState, active: id } }); } <div key={list.id} className={`${list.id === active ? `${style.active} ${style.dot}` : `${style.dot}`}`} onClick={() => scrollToElement(list.id, list.name)} />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Está devolviendo un objeto para un nuevo valor de estado.

Prueba esto:

 const [active, setActive] = useState(1); const scrollToElement = (id, value) => { const element = document.getElementById(`${value}`); element.scrollIntoView({ behavior: 'smooth' }); setActive(id); } <div key={list.id} className={`${list.id === active ? `${style.active} ${style.dot}` : `${style.dot}`}`} onClick={() => scrollToElement(list.id, list.name)} />
about 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
Show me some job opportunities
There's an error!