我是 React 新手,我正在使用以下内容创建上传图片功能:https : //github.com/JakeHartnell/react-images-upload作为指南。
但是我在设置状态时遇到问题,即使我从上传中删除它,它也会添加文件
正如您在屏幕截图中看到的,我添加了两张照片,删除了一张,然后又添加了一张。当我检查状态时。它在数组中有 6 个文件。我该如何解决这个问题?
这是我的 onchange 功能:
onDrop = picture => {
this.setState({
artistGallery: this.state.artistGallery.concat(picture),
});
};
我在这里称它:
<ImageUploader
withIcon={true}
buttonText='Choose images'
onChange={this.onDrop}
imgExtension={['.jpg', '.gif', '.png', '.gif']}
maxFileSize={5242880}
withPreview={true}
/>