Hard
You're building a drag-and-drop file upload component with progress tracking. What's wrong with this implementation?
1function FileUploader() {2 const [files, setFiles] = useState([]);3 const [uploadProgress, setUploadProgress] = useState({});45 const handleDrop = async (acceptedFiles) => {6 setFiles(prev => [...prev, ...acceptedFiles]);78 acceptedFiles.forEach(file => {9 const formData = new FormData();10 formData.append('file', file);1112 const xhr = new XMLHttpRequest();13 xhr.open('POST', '/api/upload');1415 xhr.upload.onprogress = (event) => {16 if (event.lengthComputable) {17 const progress = (event.loaded / event.total) * 100;18 setUploadProgress(prev => ({19 ...prev,20 [file.name]: progress21 }));22 }23 };2425 xhr.onload = () => {26 if (xhr.status === 200) {27 console.log(`${file.name} uploaded successfully`);28 }29 };3031 xhr.send(formData);32 });33 };3435 return (36 <div37 onDrop={handleDrop}38 onDragOver={(e) => e.preventDefault()}39 >40 {files.map(file => (41 <div key={file.name}>42 {file.name}: {uploadProgress[file.name]}%43 </div>44 ))}45 </div>46 );47}