score:2

Accepted answer

to read multiple images:

1. first define a function that will read a single file.

2. use any loop to call that function for each entry of the array.

3. use array in state variable to store the result, instead of a single variable.

constructor(props) {
  super(props);
  this.state = {
    image: []
  };
}

use this function to read multiple files:

ondropmain(mainimage) {
    var that = this;

    function read(file){
        let reader = new filereader();
        reader.onload = function (event) {
            let image = that.state.image.slice();
            image.push(event.target.result);
            that.setstate({image}, () => console.log(image));
        };
        reader.readasdataurl(file);
    }

    if (mainimage && mainimage.length) {
        [].foreach.call(mainimage, read);
    }    
}

check the answers of this question for details about [].foreach.call(mainimage, read).


Related Query

More Query from same tag