I am implementing Dropzone area in React JS. I would like to display in a text field the file name that is currently being uploaded.
The problem is that react postpone calling render() method until the end of the forEach loop. The file names are logged dynamically (console.log) but the text field (dropzoneText) does not change in the view during the loop execution. After the end of the loop react render() the view with the last state - the last file name in the queue.
I found one case which seems to be similar using https://facebook.github.io/react/docs/clone-with-props.html feature, but it seems to be the workaround.
I would appreciate any help.
//...
import Dropzone from 'react-dropzone';
class SampleDropzone extends React.Component{
constructor(props, context) {
console.log("Recruitment constructor");
super(props, context);
this.state = {
dropzoneText: "Drop your files here..."
};
}
wait(ms){
var start = new Date().getTime();
var end = start;
while(end < start + ms) {
end = new Date().getTime();
}
}
onDrop(files) {
files.forEach((file)=> {
console.log('Received file: ', file.name);
this.setState({dropzoneText: file.name});
//this.saveFileToServerFromDropzone(file);
this.wait(1000)
});
}
render() {
return(
<div>
<Dropzone onDrop={this.onDrop.bind(this)}>
{this.state.dropzoneText}
</Dropzone>
</div>
);
}
};