I implemented the file upload function using <input type="file" .../>
.
But I wanted to try drag and drop function, so I imported ant design.
In input tag, I used onChange to setState, but I don't know what to do with dragger tag.
Below is the source code using input tag.
onFileChange = (e) => {
this.setState({
thumbnail: e.target.files[0]
});
}
.
.
.
<Input type="file" namge="thumbnail" size="large" placeholder="Thumbnail" onChange={this.onFileChange}></Input>
and this is the ant desing's Dragger.
const { Dragger } = Upload;
const props = {
name: 'file',
multiple: true,
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
onChange(info) {
const { status } = info.file;
if (status !== 'uploading') {
console.log(info.file, info.fileList);
}
if (status === 'done') {
message.success(`${info.file.name} file uploaded successfully.`);
} else if (status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
.
.
.
<Dragger {...props}>
<p> ... </p>
</Dragger>
Is it okay to attach "onchange" to the dragger with props like this?
<Dragger {...props} onChange={this.onFileChange}>
<p> ... </p>
</Dragger>
I'd appreciate your help.