'multible file uploads using ract.js, and normal input stuff

I'm building an app where I have an input to upload one image and it works fine, but now I wonna build a multiple image uploader where a user can go in and add multiple image,

the logic I used to upload only one image is:

  const handleCaptureChange =
    (prop: keyof State) => (event: React.ChangeEvent<HTMLInputElement>) => {
      const files = event?.target?.files;
      if (files) {
        const reader = new FileReader();
        let url = reader.readAsDataURL(files[0]);
        reader.onloadend = (e) => {
          if (typeof reader.result === 'string') {
            setValues({ ...values, profileImg: reader.result });
          }
          //
        };
      } else {
        setValues({
          ...values,
          [prop]: event.target.value,
        });
        }
      }
    };

where my values hold all the data, instead of creating a multiple setStates, it's in one called values.

to make this value accepts multiple images I added this multiple to the input itself, but now I need to handle the above handleCaptureChange function to accept multiple values, right?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source