Skip to content

Commit

Permalink
refactor: update the remove method to avoid direct state update
Browse files Browse the repository at this point in the history
- Create a clone of fileList before removing the file
- Remove the file and update state with the setter
  • Loading branch information
Mike-Heneghan committed Nov 13, 2023
1 parent e3158fc commit 3f5a688
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ function Component(props: Props) {
),
);
setFileUploadStatus(`${slot.file.path} was deleted`);
removeSlots(
const updatedFileList = removeSlots(
getTagsForSlot(slot.id, fileList),
slot,
fileList,
);
setFileList(updatedFileList);
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cloneDeep from "lodash/cloneDeep";
import merge from "lodash/merge";
import sortBy from "lodash/sortBy";
import uniqBy from "lodash/uniqBy";
import { Store } from "pages/FlowEditor/lib/store";
Expand Down Expand Up @@ -368,7 +367,7 @@ export const removeSlots = (
uploadedFile: FileUploadSlot,
fileList: FileList,
): FileList => {
const updatedFileList: FileList = merge(fileList);
const updatedFileList: FileList = cloneDeep(fileList);
const categories = Object.keys(updatedFileList) as Array<
keyof typeof updatedFileList
>;
Expand Down

0 comments on commit 3f5a688

Please sign in to comment.