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

127
Views
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 answers
Answer question

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 Report
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!