好的,我在这里无所适从。我在使用 Hooks 的功能组件中使用 FilePond 和 React。我没有使用 FilePond 来处理实际的上传,只是用文件设置状态,我的简化版本是这样的:
档案池:
<FilePond
onupdatefiles={fileItems => handleFilepondUpdate(fileItems)}
/>
</Form.Field>
手柄更新:
const handleFilepondUpdate = fileItems => {
if (fileItems.length === 0) {
addAttachment({
...picture,
bugAttachment: null
});
} else {
addAttachment({
...picture,
bugAttachment: fileItems[0].file
});
}
};
状态:
const [picture, addAttachment] = useState({
bugAttachment: ""
});
const { bugAttachment } = picture;
最后我上传并清除输入状态:
const onSubmit = e => {
e.preventDefault();
const fd = new FormData();
fd.append("email", props.user[0].email);
fd.append("bugDescription", bugDescription);
fd.append("bugAttachment", bugAttachment);
addBug(fd).then(() => {
setBug({
bugDescription: ""
});
});
};
那么在发送表单后,我将如何删除 FilePond 文件呢?