1- import { useState } from "react" ;
1+ import { useCallback , useState } from "react" ;
22import { useForm } from "react-hook-form" ;
33import { zodResolver } from "@hookform/resolvers/zod" ;
44import {
@@ -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