melhore e otimize o código react import { FC, useMemo } from "react"; const formatBytes…
- User
melhore e otimize o código react
import { FC, useMemo } from "react";
const formatBytes = (bytes: number) => { const units = ["B", "KB", "MB", "GB"]; let index = 0;
while (bytes >= 1024) { index++; bytes /= 1024; }
return
${bytes.toFixed(2)} ${units[index]}; };interface DownloadProgressProps { currentFile: number; totalFiles: number; fileName: string; downloadedBytes: number; totalBytes: number; }
const DownloadProgress: FC = ({currentFile, totalFiles, fileName, downloadedBytes, totalBytes,}) => { const progressPercent = useMemo(() => (downloadedBytes / totalBytes) * 100, [downloadedBytes, totalBytes]);
const totalFilesLength = String(totalFiles).length; const formattedCurrentFile = String(currentFile).padStart(totalFilesLength, "0");
return ( Baixando arquivo ({formattedCurrentFile} / {totalFiles}): {fileName} ( {formatBytes(downloadedBytes)} {" "} / {formatBytes(totalBytes)})
code<div className="w-[95%] bg-[#0E1622]/[0.95] rounded-md h-5 flex items-center"> <div className="bg-[#1164CA]/[0.95] ml-1 rounded-md h-4 transition-all duration-300" style={{ width: `${progressPercent}%` }} /> </div> </div>); };
export default DownloadProgress;
- Assistant