Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
Uploading File doesn't let me pick same file after I remove it from selection in react

in react when we clear the file by clicking cross button we are not able to select the same file. How to write the function that after removing existing file if user again want to pick the same file file should not be selected .If you want to select rather than existing file then file should be selected.

  import React from "react";
export default function DropDown() {
const [checked, setChecked] = React.useState(false);
function fun(e)
{
  let file=e.target.files[0];
  localStorage.setItem("selectedFile",file.name);
  if (localStorage.getItem("selectedFile")===file.name) 
  {
    alert('duplicate');
   // document.getElementById("file").value = '';
  //setChecked(false);
  } 
  else 
  {
    alert('not duplicate');
    //setChecked(true);
  }
  console.log(localStorage.selectedFile);
}
return (
    <div >
     <input type="file"  id="file" onChange={(e) => {setChecked(true);fun(e)}} />
    {checked ?<button onClick={(e)=>{setChecked(false);document.getElementById("file").value = '';}}>x</button>:null}
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda