Skip to content

Commit

Permalink
refactor: useEffect 내부 함수 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
ljh0608 committed Aug 7, 2024
1 parent 6e833aa commit 00fc5d5
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/pages/selectSchedule/components/SelectScheduleTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ function SelectScheduleTable({ timeSlots, availableDates }: TimetableStructure)
};
const bottomItem = bottomItems[scheduleStep];

const resetPriorities = (selectedSlots: SelectedSlotType) => {
const updatedSelectedSlots: SelectedSlotType = {};
for (const key in selectedSlots) {
updatedSelectedSlots[key] = {
...selectedSlots[key],
priority: 0,
};
}
setSelectedSlots(updatedSelectedSlots);
};

useEffect(
() => {
if (scheduleStep === 'selectTimeSlot') {
const resetPriorities = () => {
const updatedSchedules = Object.entries(selectedSlots).map((schedule) => {
if (schedule[1] && typeof schedule[1] === 'object') {
return [schedule[0], { ...schedule[1], priority: 0 }];
}
return schedule;
});
setSelectedSlots(Object.fromEntries(updatedSchedules));
};
resetPriorities();
resetPriorities(selectedSlots);
}
},
[scheduleStep],
Expand Down

0 comments on commit 00fc5d5

Please sign in to comment.