Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
Does not re-change the audio preview. in react js

I created file upload and preview using URL.createObjectURL in the react js. when I try to put another audio, it does not re-change the audio preview. but I try to change the image, it does work

see in codesandbox

import React, {useState } from 'react';

function FileUpload() {

  const [source, SetSource] = useState('');

  const handleChange = (event) => {
    const file = event.target.files[0];

    if(!file) return;

    const url = URL.createObjectURL(file);
    const fileType = file?.type.split('/')[0];
    URL.revokeObjectURL(file); // free memory

    SetSource({ fileType, fileUrl: url});
  };

  return (
    <div>
       <input type="file" onChange={handleChange}/>

      {/* audio */}
      { source.fileType ==="audio" && (<audio controls>
              <source src={source.fileUrl} type="audio/mpeg" />
        </audio>)}

      {/* image */}
      { source.fileType=== "image" && (<img src={source.fileUrl}/>)}

    </div>
  );
}

export default FileUpload;

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda