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

276
Views
¿Por qué esto registra el valor anterior y no el valor nuevo?
const [title,setTitle] = useState(""); const titleHandler=e => { setTitle(e.target.value) console.log(title) }

¿Por qué este código registra el valor antiguo del título y no el nuevo? Soy nuevo en js y reacciono, por favor, ¿alguien puede explicarme esto?

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

0

sucedió porque cuando llamas a setTitle no actualiza el estado instantáneamente, pero activa una nueva representación del componente con el estado actualizado

si lo haces

 const [title,setTitle] = useState(""); const titleHandler=e => { setTitle(e.target.value) console.log('updating title') } useEffect(() => { console.log('title updated', title) }, [title])

Puedes verlo por ti mismo

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