@@ -6,24 +6,28 @@ import { useNavigate } from 'react-router-dom';
66import { FormData , zodValidation } from '../../shared/lib/formValidation' ;
77import { useUserInfo , useUserUpdate } from '../../features/join/hooks/useUserHook' ;
88import useAuthStore from '../../app/provider/authStore' ;
9+ import { useEffect } from 'react' ;
910
1011const InfoInputPage = ( ) => {
1112 const { data, isLoading } = useUserInfo ( ) ;
12- const { login, setName} = useAuthStore ( ) ;
13+ const { login, setName } = useAuthStore ( ) ;
1314 const { mutate : updateUser } = useUserUpdate ( ) ;
1415 const {
1516 register,
1617 handleSubmit,
1718 formState : { errors, isValid } ,
19+ reset,
1820 } = useForm < FormData > ( {
1921 mode : 'onChange' ,
22+ defaultValues : {
23+ name : '' ,
24+ email : '' ,
25+ phone : '' ,
26+ } ,
2027 ...zodValidation ,
2128 } ) ;
2229 const navigate = useNavigate ( ) ;
2330
24- const nameValue = data ?. name ;
25- const emailValue = data ?. email ;
26-
2731 const onSubmit : SubmitHandler < FormData > = formData => {
2832 const updatedData = {
2933 id : data ?. id || 0 ,
@@ -44,7 +48,15 @@ const InfoInputPage = () => {
4448 } ,
4549 } ) ;
4650 } ;
47-
51+ useEffect ( ( ) => {
52+ if ( data ) {
53+ reset ( {
54+ name : data . name || '' ,
55+ email : data . email || '' ,
56+ phone : '' ,
57+ } ) ;
58+ }
59+ } , [ data , reset ] ) ;
4860 if ( isLoading ) {
4961 return < div > 로딩 중...</ div > ;
5062 }
@@ -62,7 +74,6 @@ const InfoInputPage = () => {
6274 < UnderlineTextField
6375 label = "이름"
6476 placeholder = "이름"
65- value = { nameValue }
6677 errorMessage = { errors . name ?. message }
6778 className = "text-xl"
6879 { ...register ( 'name' ) }
@@ -82,7 +93,6 @@ const InfoInputPage = () => {
8293 < UnderlineTextField
8394 label = "이메일"
8495 placeholder = "이메일"
85- value = { emailValue }
8696 type = "email"
8797 errorMessage = { errors . email ?. message }
8898 className = "text-xl"
0 commit comments