@@ -3,6 +3,7 @@ import SpinLoading from '@/components/loading/SpinLoading';
33import { MAX_NICKNAME_LENGTH , MIN_NICKNAME_LENGTH , NICKNAME_REGEX } from '@/constants' ;
44import { useNicknameAvailability } from '@/hooks/useNicknameAvailability' ;
55import { useValidationWithButton } from '@/hooks/useValidationWithButton' ;
6+ import { useEffect , useState } from 'react' ;
67
78interface NicknameInputProps {
89 initialValue ?: string ; // 초기값
@@ -12,6 +13,7 @@ interface NicknameInputProps {
1213}
1314
1415function NicknameInput ( { initialValue, setValue, validity, setValidity } : NicknameInputProps ) {
16+ const [ showLoading , setShowLoading ] = useState ( false ) ; // 로딩 UI 표시 여부
1517 // 유효성 검사
1618 const handleValidation = ( value : string ) => {
1719 if ( value . length < MIN_NICKNAME_LENGTH || value . length > MAX_NICKNAME_LENGTH ) {
@@ -43,8 +45,19 @@ function NicknameInput({ initialValue, setValue, validity, setValidity }: Nickna
4345 setValidationMessage ,
4446 ) ;
4547
46- const renderButtonContent = ( ) => {
48+ // 0.1초 후 로딩 UI 표시
49+ useEffect ( ( ) => {
50+ let loadingTimeout : NodeJS . Timeout ;
4751 if ( isPending ) {
52+ loadingTimeout = setTimeout ( ( ) => setShowLoading ( true ) , 100 ) ;
53+ } else {
54+ setShowLoading ( false ) ;
55+ }
56+ return ( ) => clearTimeout ( loadingTimeout ) ;
57+ } , [ isPending ] ) ;
58+
59+ const renderButtonContent = ( ) => {
60+ if ( showLoading ) {
4861 return < SpinLoading /> ;
4962 } else return < span > 중복확인</ span > ;
5063 } ;
0 commit comments