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

191
Views
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
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!