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)} /> + 번호 이름