Skip to content

Commit e1b8621

Browse files
committed
feat: 회원가입 버튼에 throttle 추가
1 parent 4366218 commit e1b8621

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/pages/signup/components/IdInput.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { InputField } from '@/components/input';
55
import { ID_REGEX } from '@/constants';
66
import { useModalStore } from '@/store/modalStore';
77
import { useMutation } from '@tanstack/react-query';
8-
import { useState } from 'react';
8+
import { throttle } from 'lodash';
9+
import { useMemo, useState } from 'react';
910

1011
interface IdInputProps {
1112
setValidity: (val: boolean) => void;
@@ -56,6 +57,8 @@ const IdInput = ({ setValidity }: IdInputProps) => {
5657
},
5758
});
5859

60+
const throttledMutate = useMemo(() => throttle((value: string) => mutate(value), 1000), [mutate]);
61+
5962
return (
6063
<InputField
6164
id="id"
@@ -72,7 +75,7 @@ const IdInput = ({ setValidity }: IdInputProps) => {
7275
className="w-[65px]"
7376
text="중복확인"
7477
disabled={!validationStatus.isValid}
75-
onClick={() => mutate(text)}
78+
onClick={() => throttledMutate(text)}
7679
/>
7780
}
7881
/>

src/pages/signup/components/NicknameInput.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { LoadingSpinnerButton } from '@/components/button';
33
import { InputField } from '@/components/input';
44
import { MAX_NICKNAME_LENGTH, MIN_NICKNAME_LENGTH, NICKNAME_REGEX } from '@/constants';
55
import { useMutation } from '@tanstack/react-query';
6-
import { useEffect, useState } from 'react';
6+
import { throttle } from 'lodash';
7+
import { useEffect, useMemo, useState } from 'react';
78

89
interface NicknameInputProps {
910
initialText?: string; // 초기값
@@ -42,7 +43,7 @@ function NicknameInput({ initialText = '', setValidity }: NicknameInputProps) {
4243
};
4344
// 닉네임 중복을 확인하는 함수
4445
const { mutate, isPending } = useMutation({
45-
mutationFn: () => getNicknameAvailability(text),
46+
mutationFn: (value: string) => getNicknameAvailability(value),
4647
onSuccess: (data) => {
4748
if (data.code === 200) {
4849
setValidationStatus({ isValid: true, message: '사용 가능한 닉네임입니다' });
@@ -64,6 +65,8 @@ function NicknameInput({ initialText = '', setValidity }: NicknameInputProps) {
6465
setText(initialText);
6566
}, [initialText]);
6667

68+
const throttledMutate = useMemo(() => throttle((value: string) => mutate(value), 1000), [mutate]);
69+
6770
return (
6871
<InputField
6972
id="nickname"
@@ -80,7 +83,7 @@ function NicknameInput({ initialText = '', setValidity }: NicknameInputProps) {
8083
className="w-[65px]"
8184
text="중복확인"
8285
disabled={!validationStatus.isValid}
83-
onClick={() => mutate()}
86+
onClick={() => throttledMutate(text)}
8487
/>
8588
}
8689
/>

0 commit comments

Comments
 (0)