import React, { useState } from 'react'; import { UploadOutlined } from '@ant-design/icons'; import { Button, message, Upload } from 'antd'; import type { GetProp, UploadFile, UploadProps } from 'antd'; type FileType = Parameters>[0]; const App: React.FC = () => { const [fileList, setFileList] = useState([]); const [uploading, setUploading] = useState(false); const handleUpload = () => { const formData = new FormData(); fileList.forEach((file) => { formData.append('files[]', file as FileType); }); setUploading(true); // You can use any AJAX library you like fetch('https://660d2bd96ddfa2943b33731c.mockapi.io/api/upload', { method: 'POST', body: formData, }) .then((res) => res.json()) .then(() => { setFileList([]); message.success('upload successfully.'); }) .catch(() => { message.error('upload failed.'); }) .finally(() => { setUploading(false); }); }; const props: UploadProps = { onRemove: (file) => { const index = fileList.indexOf(file); const newFileList = fileList.slice(); newFileList.splice(index, 1); setFileList(newFileList); }, beforeUpload: (file) => { setFileList([...fileList, file]); return false; }, fileList, }; return ( <> ); }; export default App;