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

129
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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