0

So i tried to create a new object as a solution for an issue that I had in my code. But when I tried to create a new object with the updated values it doesn't return the old values. just the updated value. what could be the issue? Had to create a new object instead of modifying the existing one because some values are read only.

Here is the function that check for duplicate files,

 const beforeUpload = (event: any) => {
  const file: any = event?.target?.files[0];
  const duplicateFile= fileList.find((files)=>{
    return files.name==file?.name;
  })
  if(duplicateFile){
    console.log(duplicateFile);
    
    const updatedFile={
      ...duplicateFile,
      name:`${duplicateFile.name}(${duplicateCount})`
    };
    console.log(updatedFile);
    setDuplicateCount(duplicateCount+1);
    
  }
  

  if (!file) {
    return;
  }

takes a file and checks whether the file name already exists or not. And add a number to the end of the file name. i want to create a new object with the update name. Thats where I get the issue.

Here is the console output, The object on the top is what function receiving and the bottom one is the output. TIA.

enter image description here

2
  • 1
    Don't really understand the question but a heads up. I'm pretty sure the (1) or (4) should be after the file name and before the extension name. eg. example(1).png Commented Jan 3, 2023 at 9:46
  • Spread only copies the enumerable own properties. Whatever property you aren't seeing in the updatedFile are not enumerable. Check the duplicates on how to correctly clone a file obejct. Commented Jan 3, 2023 at 9:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.