Skip to content
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

[ Async Search with Debounce and Creatable ] is always in the loading state #73

Closed
lumpinif opened this issue Apr 19, 2024 · 1 comment

Comments

@lumpinif
Copy link
Contributor

image image

To be noticed: The code for Implementing the muti-select is the same as the one from [ Async Search with Debounce and Creatable ], I copy and paste it into my nextjs project.

Issue: When the loading state is triggered, it seems unstoppable to complete the search, until clear out the input then the results finally show up.

@lumpinif
Copy link
Contributor Author

updates:

It's solved. It turns out I accidentally auto-updates the deps of onSearch in the useEffect of doSearch.
It is working as expected after I removed the onSearch and disable the eslint.

useEffect(() => {
  const doSearch = async () => {
    setIsLoading(true)
    const res = await onSearch?.(debouncedSearchTerm)
    setOptions(transToGroupOption(res || [], groupBy))
    setIsLoading(false)
  }

  const exec = async () => {
    if (!onSearch || !open) return

    if (triggerSearchOnFocus) {
      await doSearch()
    }

    if (debouncedSearchTerm) {
      await doSearch()
    }
  }

  void exec()
  // eslint-disable-next-line react-hooks/exhaustive-deps
}, [debouncedSearchTerm, groupBy, open, triggerSearchOnFocus]) 

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

No branches or pull requests

1 participant