Некорректный тип значения
У меня есть объект следующего вида:
file: {
createdAt: "2024-08-11T08:14:23.794Z",
filename: "4kz0phxsmg.mp4",
filesize: 2860606,
id: "66b872df4996ceba0199fbbc",
mimeType: "video/mp4",
name: "Russian (ru)",
updatedAt: "2024-08-11T08:14:23.794Z",
url: "/media/4kz0phxsmg.mp4"}
Я передаю значение в функцию из объекта следующим способом:
LogoView(file.filename)
функция
const LogoView = (Doc: any) => {
console.log(typeof Doc,Doc)
;}
Но вместо того, чтобы увидеть в логе значение '4kz0phxsmg.mp4'
, получаю объект с этим значением: {Doc: '4kz0phxsmg.mp4'}
.
Кто сможет объяснить, почему так происходит?
Дополнения:
полный код элемента
import React from "react";
import { ReactComponent as DownloadIcon } from "shared/assets/svg/bootstrap-icons-1.11.2/download.svg";
import { ReactComponent as Excel } from "shared/assets/svg/SVG-DOCS-ICONS/excel-document-svgrepo-com.svg";
import { ReactComponent as Powerpoint } from "shared/assets/svg/SVG-DOCS-ICONS/ppt-document-svgrepo-com.svg";
import { ReactComponent as Word } from "shared/assets/svg/SVG-DOCS-ICONS/word-document-svgrepo-com.svg";
import { ReactComponent as PDF } from "shared/assets/svg/SVG-DOCS-ICONS/pdf-document-svgrepo-com.svg";
import { ReactComponent as FileUnknown } from "shared/assets/svg/SVG-DOCS-ICONS/unknown-document-svgrepo-com.svg";
import { ReactComponent as Xml } from "shared/assets/svg/SVG-DOCS-ICONS/xml-document-svgrepo-com.svg";
import { ReactComponent as Zip } from "shared/assets/svg/SVG-DOCS-ICONS/zip-document-svgrepo-com.svg";
import { ReactComponent as Video_File } from "shared/assets/svg/SVG-DOCS-ICONS/video-document-svgrepo-com.svg";
import { ReactComponent as Music_File } from "shared/assets/svg/SVG-DOCS-ICONS//audio-document-svgrepo-com.svg";
import { ReactComponent as Txt } from "shared/assets/svg/SVG-DOCS-ICONS/txt-document-svgrepo-com.svg";
import "./Files.scss";
import { Button } from "shared/ui/button";
type Props = {
files: any;
};
const word: string[] = ["doc", "docx", "docm", "dotx", "dotm", "rtf"];
const excel: string[] = [
"xls",
"xlt",
"xlm",
"xlsx",
"xlsm",
"xltx",
"xltm",
"xlsb",
"xla",
"xlam",
"xll",
"xlw",
];
const powerpoint: string[] = [
"ppt",
"ppt",
"pot",
"pps",
"ppa",
"ppam",
"pptx ",
"pptm",
"potx",
"potm",
"ppam",
"ppsx",
"ppsm",
"sldx",
"sldm",
"pa",
];
const zip: string[] = ["zip", "rar", "7z", "gzip"];
const Fvideo: string[] = ["mp4", "ogv", "webm"];
const Fmusic: string[] = ["mp3", "ogg", "wav"];
export const Files = ({ files }: Props) => {
const LogoView = (Doc: any) => {
console.log(typeof Doc,Doc);
Doc = Doc.Doc;
const FileType: string = Doc.split(".").pop();
console.log(typeof Doc,Doc);
if (word.includes(FileType)) {
return <Word />;
} else if (excel.includes(FileType)) {
return <Excel />;
} else if (powerpoint.includes(FileType)) {
return <Powerpoint />;
} else if (zip.includes(FileType)) {
return <Zip />;
} else if (Fvideo.includes(FileType)) {
return <Music_File />;
} else if (Fmusic.includes(FileType)) {
return <Video_File />;
} else if (FileType === "pdf") {
return <PDF />;
} else if (FileType === "xml") {
return <Xml />;
} else if (FileType === "txt") {
return <Txt />;
} else {
return <FileUnknown />;
}
};
return (
<div className="block__files">
{files.map((item: any) => {
return (
<div className="file__wrap">
<div className="file__icon">
<LogoView Doc={item.file.filename} />
</div>
<div className="name-file">{item.file.name}{item.file.filename}</div>
<a href={item.file.url} download>
<Button Icon={DownloadIcon}>Скачать</Button>
</a>
</div>
);
})}
</div>
);
};
получаемый объект
files: {
[file:{
createdAt: "2024-08-11T08:14:23.794Z"
filename: "4kz0phxsmg.mp4"
filesize: 2860606
id: "66b872df4996ceba0199fbbc"
mimeType: "video/mp4"
name: "Russian (ru)"
updatedAt: "2024-08-11T08:14:23.794Z"
url: "/media/4kz0phxsmg.mp4"
},
file:{
createdAt: "2024-08-11T08:14:39.339Z"
filename: "nq8wc1jctsi.jpg"
filesize: 105882
id: "66b872ef4996ceba0199fbc3"
mimeType: "image/jpeg"
name: "there"
updatedAt: "2024-08-11T08:14:39.339Z"
url: "/media/nq8wc1jctsi.jpg"}]}