정말 계속 해봤는데 아무리 해도 해결을 못 했어요..ㅠㅠ
몇 일 해서 이정도도 못 하는데 계속 공부하는게 맞나 싶기도 하고 허ㅓ허
체크박스 전체선택, 일부선택 때 사용한 코드인데 이거 사용해서 checkedState가 true일 때를 시도해봤어요
const [isAllChecked, setAllChecked] = useState(false);
const [checkedState, setCheckedState] = useState(new Array(state.cart.length).fill(false));
const handleAllCheck = () => {
setAllChecked((prev) => !prev);
let array = new Array(state.cart.length).fill(!isAllChecked);
setCheckedState(array);
};
const handleMonoCheck = (position) => {
const updatedCheckedState = checkedState.map((item, index) =>
index === position ? !item : item
);
setCheckedState(updatedCheckedState);
const checkedLength = updatedCheckedState.reduce((sum, currentState) => {
if (currentState === true) {
return sum + 1;
}
return sum;
}, 0);
setAllChecked(checkedLength === updatedCheckedState.length);
};
input 태그의 onChange안에서도 함수 만들어보고 이것저것 시도해봤는데 하나도 못 풀고 영 진도를 못 뺐습니다ㅠㅠ