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

111
Views
El componente React no se vuelve a renderizar incluso si se actualiza el estado

Actualmente estoy usando wavesurfer.js para reproducir un archivo de audio. He creado un useRef para wavesurfer. En la primera carga, creo una instancia de WaveSurfer y la asigno a wavesurferRef. Actualmente estoy ejecutando este código también

 const [timeRemaining, setTimeRemaining] = useState('') useEffect(() => { if (playing && wavesurfer.current) { wavesurfer.current.on('audioprocess', function () { if (wavesurfer.current?.isPlaying()) { const totalTime = wavesurfer.current.getDuration() const currentTime = wavesurfer.current.getCurrentTime() setTimeRemaining(`-${Math.round(totalTime - currentTime)}`) } }) } }, [playing])

Desde mi comprensión de useState. El componente debe volver a procesarse cada vez que cambia el estado, así que suponga que, dado que se llama a setTimeRemaining cada milisegundo, el componente debería volver a procesarse, pero cuando verifico los registros. El useEffects que se carga en el montaje del componente no se vuelve a ejecutar.

¿Por qué no se vuelve a renderizar mi componente?

Idealmente, en lugar de useState, debería usar useRef para el valor de timeRemaining pero cuando uso useRef, el div que muestra el valor de timeRemaining no muestra el nuevo valor de timeRemaining ref.

Aquí hay un ejemplo de stackblitz que contiene un ejemplo para el enfoque usestate y useref

https://stackblitz.com/edit/react-ts-kcrfuy?file=index.tsx

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!