SoAanyip / React-FileUpload

Upload files async with xhr2 or iframe for IE. Supporting IE8+. React component.
310 stars 95 forks source link

support arrow function #19

Closed wubocong closed 7 years ago

wubocong commented 8 years ago

chooseFile: (files) => { this.state.files = files; this.props.creatingFiles(); return true; } when I did this, I couldn't get the files' list, I guess possibly the problem of this pointer

Pritoj commented 8 years ago

This is not an arrow function problem but a problem with binding.

I think this should work...

var chooseFile = (files) => { this.state.files = files; this.props.creatingFiles(); return true; };

var options = {
chooseFile : chooseFile.bind(this);
}
wubocong commented 8 years ago

@Pritoj No, that's not the point, I find it difficult to handle state using this component because it doesn't have a parent pointer.

SoAanyip commented 8 years ago

@wubocong I tried and got this as the React component:

<FileUpload options={{
  baseUrl: '/upload',
  chooseFile:(file)=> {
    console.log(this)
  }
}}>

Can I know what you got by logging this ?

wubocong commented 7 years ago

I found this problem if using es5 function incorrectly. Besides I figure out that the Filelist object can't be enumerable, so I manually reassembled it and refactored your code. I have created a new repository react-upload-file. Comments welcomed!