Skip to content

Conversation

wo-o29
Copy link
Contributor

@wo-o29 wo-o29 commented Sep 12, 2025

Overview

This PR fixes issues in the AutoCompleteInput example code in the documentation:

  1. Removed duplicated clearTimeout(searchTimeoutRef.current) logic and kept cleanup-only execution.
  2. Simplified useOutsideClickEffect usage by directly passing closeSearchBox.
  3. Corrected Separated component prop from with to by, which matches the correct API signature.

These changes make the docs match the intended API usage and improve readability for contributors and users.

Checklist

  • Did you write the test code? (Not applicable, documentation only)
  • Have you run yarn run fix to format and lint the code and docs?
  • Have you run yarn run test:coverage to make sure there is no uncovered line? (Not applicable, documentation only)
  • Did you write the JSDoc? (Not applicable, documentation only)

additinal comment

react-simplikit, 선택의 이유 docs with-react-simplikit.tsx In the example code, searchResults is an asynchronous function, so TypeScript infers its return type as Promise<void>.

However, the debounced function returned by useDebounce is designed to return void when called, so its actual runtime return type is void.

Therefore, passing it as an argument to startLoading, which expects a Promise, causes a type error.

const [isLoading, startLoading] = useLoading();
const searchResults = useDebounce(async (searchQuery: string) => {
  if (searchQuery.trim().length === 0) {
    setResults([]);
    return;
  }

  const response = await fetch(`/api/search?q=${searchQuery}`)
    .then(res => res.json())
    .catch(error => {
      console.error('Failed to fetch results:', error);
      return [];
    });

  setResults(response);
}, 300);

<input
  type="text"
  value={query}
  onChange={e => {
    setQuery(e.target.value);
    openSearchBox();
    startLoading(searchResults(e.target.value)); // type error!
  }}
  onFocus={openSearchBox}
  placeholder="검색어를 입력하세요"
/>

To fix this, either the return type of debounce should be changed to Promise<void>

export type DebouncedFunction<F extends (...args: any[]) => void> = {
  (...args: Parameters<F>): Promise<void>;
  cancel: () => void;
};

or in the example code, startLoading should be called with an explicit Promise, like this:

startLoading((async () => await searchResults(e.target.value))());

This way, the expected Promise type is matched properly.

I'd like to hear from admins on which of the two approaches would be better, or if the example should be changed!

@Copilot Copilot AI review requested due to automatic review settings September 12, 2025 05:24
@wo-o29 wo-o29 requested a review from choi2021 as a code owner September 12, 2025 05:24
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes issues in the AutoCompleteInput example code documentation to ensure the code examples are accurate and follow correct API usage.

  • Cleaned up duplicated timeout cleanup logic in the useEffect
  • Simplified useOutsideClickEffect usage by directly passing the callback function
  • Corrected the Separated component prop from with to by to match the actual API
Comments suppressed due to low confidence (1)

src/docs/ko/why-react-simplikit-matters.md:68

  • The removal of the timeout cleanup at the beginning of the useEffect is incorrect. This cleanup is necessary to cancel any pending timeout when the query changes, preventing potential race conditions and unnecessary API calls.
      if (searchTimeoutRef.current) {
        clearTimeout(searchTimeoutRef.current);
      }

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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.

1 participant