Closed wubocong closed 7 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);
}
@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.
@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
?
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!
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