Skip to content

How can i trigger async search on button click? #4379

Discussion options

You must be logged in to vote

Greetings @MohammedSaberMohammed,

Since loadOptions is triggered when the inputValue changes and is also likely tied to the AsyncSelect being focused (though this might be an incorrect assumption). It's likely possible, but seems more complex than using a regular Select.

A non-async select would give you more flexibility as to when and how you are retrieving options. To mimic the functionality you suggest, you would likely need to:

  1. Add options to state
  2. Fetch default options onMount
  3. Add isLoading to state
  4. Show/hide search button visibility on isLoading and pass as prop to Select
  5. On search, do dataFetch with your input and set mapped results as new options in state

If you have any other c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MohammedSaberMohammed
Comment options

Answer selected by MohammedSaberMohammed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants