11import { useEffect , useState } from 'react' ;
22
3+ interface useValidationWithButtonProps {
4+ validity : boolean ; // 유효성
5+ setValidity : ( val : boolean ) => void ; // 유효성 변경 함수
6+ handleValidationMessage : ( val : string ) => { success : boolean ; message : string } ; // 유효성 메시지 관리하는 함수
7+ REGEX : RegExp ; // 정규표현식
8+ initialMessage ?: string ; // 선택적 초기 메시지
9+ initialText ?: string ; // 기본값 설정
10+ }
11+
312// 유효성 검사와 버튼 상태를 함께 관리하는 훅
4- export const useValidationWithButton = (
5- validity : boolean , // 유효성
6- setValidity : ( val : boolean ) => void , // 유효성 변경 함수
7- handleValidationMessage : ( val : string ) => { success : boolean ; message : string } , // 유효성 메시지 관리하는 함수
8- REGEX : RegExp , // 정규표현식
9- initialMessage ?: string , // 선택적 초기 메시지
10- ) => {
11- const [ text , setText ] = useState ( '' ) ;
13+ export const useValidationWithButton = ( {
14+ validity,
15+ setValidity,
16+ handleValidationMessage,
17+ REGEX ,
18+ initialMessage = '' , // 기본값 설정
19+ initialText = '' , // 기본값 설정
20+ } : useValidationWithButtonProps ) => {
21+ const [ text , setText ] = useState ( initialText ) ;
1222 const [ validationMessage , setValidationMessage ] = useState ( {
1323 success : false ,
14- message : initialMessage ?? '' ,
24+ message : initialMessage ,
1525 } ) ;
1626 const [ buttonVariant , setButtonVariant ] = useState < 'primary' | 'disabled' > ( 'disabled' ) ;
1727
@@ -34,6 +44,11 @@ export const useValidationWithButton = (
3444 }
3545 } , [ text ] ) ;
3646
47+ // 초기값 로직 수정
48+ useEffect ( ( ) => {
49+ setText ( initialText ) ;
50+ } , [ initialText ] ) ;
51+
3752 return {
3853 text,
3954 setText,
0 commit comments