Skip to content

[URH-43] useDebounce 신규 #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024
Merged

[URH-43] useDebounce 신규 #38

merged 1 commit into from
Aug 5, 2024

Conversation

suhyeoonn
Copy link
Contributor

👾 Pull Request

  • 상태: 신규

1️⃣ Spec

  • useDebounce 훅은 주어진 콜백 함수가 일정 시간(delay) 동안 호출되지 않을 때까지 콜백 함수의 실행을 지연시킵니다.

2️⃣ 변경 사항

  • 없음

3️⃣ 예시 코드

function App() {
  const [searchText, setSearchText] = useState('');
  const [debouncedText, setDebouncedText] = useState(searchText);
  const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
    const newValue = e.target.value;
    setSearchText(newValue);
    debounceSearchText(newValue);
  };

  const debounceSearchText = useDebounce((text: string) => {
    setDebouncedText(text);
  }, 200);

  const filteredUsers = users.filter((u) =>
    u.name.toLowerCase().includes(debouncedText.toLowerCase())
  );

  return (
    <div>
      <input type="text" value={searchText} onChange={handleChange} />
      <ul>
        {filteredUsers.map((u) => (
          <li key={u.id}>{u.name}</li>
        ))}
      </ul>
    </div>
  );
}

4️⃣ 관련 문서 (선택 사항)

  • 없음

Copy link
Member

@Choozii Choozii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Copy link
Collaborator

@foresec foresec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다! debounce...진짜 필요한 훅이죠

Copy link
Collaborator

@foresec foresec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

✅ test: useDebounce 테스트 코드 추가

📝 docs: useDebounce JSDoc 작성

🩹 chore: 인자로 값이 아닌 콜백 함수를 받도록 수정

📝 docs: useDebounce JSDoc 내용 수정

✅ test: useDebounce 콜백 함수 지연 방식 맞게 테스트 코드 수정

🩹 chore: useDebounce 타입을 GenericFn을 사용하여 타입 안전성 개선

✅ test: useDebounce 훅 테스트 케이스 추가
@suhyeoonn suhyeoonn force-pushed the URH-43/useDebounce branch from c8a35ed to 13557f0 Compare August 5, 2024 21:52
@suhyeoonn suhyeoonn merged commit 7d67611 into master Aug 5, 2024
@suhyeoonn suhyeoonn deleted the URH-43/useDebounce branch August 5, 2024 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants