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

131
Visualizações
file input ref triggering file-picker twice

File input ref is triggering twice when I click button multiple times very quickly -

<input
    type="file"
    ref={uploadRef}
    ...
/>
<DefaultButton
    onClick={onClick}
    ...
/>

and,

const onClick = React.useCallback(
    (e) => {
        uploadRef.current?.click();
        // e.stopPropagation();
        }
    },
    []

Related info - I tried e.stopPropagation() mentioned here - https://github.com/reactjs/react-modal/issues/494. This doesn't work.

The Button onclick multiple times "quickly" loads two file pickers in sequence. If I close first, immediately I see next one and the last selection persists.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can try to have timeout for that click event

let timer //initialise timer somewhere
const onClick = React.useCallback(
    () => {
        //remove the previous timer, once an user clicks again
        timer && clearTimeout(timer)
        timer = setTimeout(() => {
           uploadRef.current?.click();
        }, 200) // this is an idle time before opening file picker, it works for me, you can modify it as you wish
     },
    [timer])

about 4 years ago · Juan Pablo Isaza Relatório
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