Second use of input file doesn’t trigger onchange anymore

If you’re using React or just javascript in general you can what you can also do is “reset” the value of the event target.

So If you have something like a component that can upload and “remove” an image:

<input type="file" onChange={onChange} />

your onChange can be:

onChange(event) {

    const files = event.target.files;

    // your logic here on what to do with files (maybe fetch the preview or something)

    // this line right below will reset the 
    // input field so if you removed it you can re-add the same file
    event.target.value=""
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)