From 06adbb1bdaba383e138e1a2563cf16f955f9963c Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:38:26 -0400 Subject: [PATCH] fix: checking all works via updated state making sure next loop uses updated state --- src/components/DataForm.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/DataForm.tsx b/src/components/DataForm.tsx index 2396a4f..d5dabf4 100644 --- a/src/components/DataForm.tsx +++ b/src/components/DataForm.tsx @@ -33,13 +33,13 @@ const DataForm: React.FC = ({ allFiles }) => { * with the new value for `selected`. */ const updateFileList = ({ file: targetFile }: FileItem, selection: boolean) => { - const updatedFiles = files.map(({ file, selected, ...rest }) => { - return file === targetFile - ? { file, selected: selection, ...rest } - : { file, selected, ...rest } + setFiles((prevFiles) => { + return prevFiles.map(({ file, selected, ...rest }) => { + return file === targetFile + ? { file, selected: selection, ...rest } + : { file, selected, ...rest } + }) }) - - setFiles(updatedFiles) } return (