From c7fffd07694d0c5a6753f5afeff3d9dc1671d39f Mon Sep 17 00:00:00 2001 From: eunxoo Date: Thu, 15 Feb 2024 16:21:18 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20=ED=95=98=EB=82=98=EB=9D=BC=EB=8F=84=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=20=EC=B7=A8=EC=86=8C=20=EC=8B=9C=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=84=A0=ED=83=9D=20=EB=B2=84=ED=8A=BC=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=20=ED=95=B4=EC=A0=9C=20(=EB=A9=B4=EC=A0=91=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=ED=8E=98=EC=9D=B4=EC=A7=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TimePosts.jsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/TimePosts.jsx b/src/components/TimePosts.jsx index 2440ef9..70a47d5 100644 --- a/src/components/TimePosts.jsx +++ b/src/components/TimePosts.jsx @@ -104,12 +104,16 @@ const TimePosts = ({ setShowPopup, }) => { const [selectedItemId, setSelectedItemId] = useState(null); + const [isAllChecked, setIsAllChecked] = useState(false); + + useEffect(() => { + setIsAllChecked(list.length > 0 && checkedItems.length === list.length); + }, [checkedItems, list]); const onCheckBoxAll = (e) => { - if (e.target.checked) { - const checkedListArr = []; - list.forEach((item) => checkedListArr.push(item.joinerId)); - setCheckedItems(checkedListArr); + if (!isAllChecked) { + const allItems = list.map((item) => item.joinerId); + setCheckedItems(allItems); } else { setCheckedItems([]); } @@ -131,7 +135,11 @@ const TimePosts = ({ - onCheckBoxAll(e)} /> + 번호 이름