reducers: {
updateCount(state, action) {
console.log(1111111111);
state.find((x) => x.id === action.payload).count += 1;
},
addItem(state, action) {
if (state.find((x) => x.id === action.payload.id)) {
updateCount(action.payload.id);
} else {
state.push(action.payload);
}
},
},
얼추 reducer 내부에 이런식으로 코드를 작성하였습니다.
아이템이 존재하면 내부에서 updatecount를 콜해서 카운트만 올려줄수 있도록요.
근데 호출을 어떤식으로 하는지 모르겠습니다.
useDispatch는 컴포넌트 레벨에서 먹히는것 같아서 안되고, 다른 내장함수가 있을것 같은데 10분정도 구글링 해도 못찾겠더라고요.
혹시 어떤식으로 콜하는지 알수 있을까요?