Skip to content

Commit 2c30d98

Browse files
committed
refactor(planner): useCallback 훅을 사용하여 초기화 및 핸들러 함수 최적화
1 parent 96c15d3 commit 2c30d98

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

src/hooks/planner/useAddScheduleForm.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useCallback, useState } from "react";
22
import { useForm } from "react-hook-form";
33
import { zodResolver } from "@hookform/resolvers/zod";
44
import {
@@ -25,7 +25,7 @@ export function useAddScheduleForm(defaultStartTime?: string) {
2525
});
2626

2727
// 초기화 로직
28-
const resetToInitialState = () => {
28+
const resetToInitialState = useCallback(() => {
2929
setCurrentScheduleType("MEAL");
3030
const initialValues = getDefaultScheduleValues("MEAL", toMinutePrecision(defaultStartTime));
3131
form.reset(initialValues, {
@@ -34,19 +34,22 @@ export function useAddScheduleForm(defaultStartTime?: string) {
3434
keepIsValid: false,
3535
keepErrors: false,
3636
});
37-
};
37+
}, [defaultStartTime, form]);
3838

3939
// scheduleType 변경 핸들러
40-
const handleScheduleTypeChange = (newType: Exclude<ScheduleType, "TRANSPORT">) => {
41-
setCurrentScheduleType(newType);
42-
const newValues = getDefaultScheduleValues(newType, toMinutePrecision(defaultStartTime));
43-
form.reset(newValues, {
44-
keepDirty: false,
45-
keepTouched: false,
46-
keepIsValid: false,
47-
keepErrors: false,
48-
});
49-
};
40+
const handleScheduleTypeChange = useCallback(
41+
(newType: Exclude<ScheduleType, "TRANSPORT">) => {
42+
setCurrentScheduleType(newType);
43+
const newValues = getDefaultScheduleValues(newType, toMinutePrecision(defaultStartTime));
44+
form.reset(newValues, {
45+
keepDirty: false,
46+
keepTouched: false,
47+
keepIsValid: false,
48+
keepErrors: false,
49+
});
50+
},
51+
[defaultStartTime, form]
52+
);
5053

5154
return {
5255
form,

0 commit comments

Comments
 (0)