question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async select option empties loadedOptions

See original GitHub issue

Hey guys, First of all thanks for the great work on this it is a pleasure to use this lib, really.

Sorry to bring back this but when using Async component I can’t figure out how to keep the options loaded. It always resets to an empty options list. Thing is on select option it calls back the handleInputChange with a newValue = "" (here https://github.com/JedWatson/react-select/blob/master/src/Async.js#L110-L134) which leads to a !inputValue = true wich leads to loadedOptions: [] instead of loadedOptions: this.optionsCache[inputValue], I tried to store the value in my internal state component using

onInputChange = (query, { action }) => {
  // Prevents resetting our input after option has been selected
  if (action !== "set-value") this.setState({inputValue: query});
}

and setting the prop inputValue as state.inputValue but it will always lead to a newValue = "" in the handleInputChange method.

Maybe it is the expected behaviour but this is really annoying as selecting an option always lead to a empty options list …

If someone found a way to avoid that behaviour I’d appreciate a lot 👍 Using v2.4.1 Happy to provide more info / understand what’s going on.

Thanks again !

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:6

github_iconTop GitHub Comments

2reactions
ebonowcommented, Dec 19, 2020

Greetings,

It would seem that this question is resolved by the answer provided directly above this by @andrewmahoneyf and would be the recommended way to approach this.

I will close this issue out but if there are any questions or concerns, please feel free to followup and this can be re-opened if necessary.

2reactions
andrewmahoneyfcommented, Mar 12, 2020

@theocousin My working solution for this going off of your temporary workaround:

  const onInputChange = (query, { action }) => {
    if (action === 'input-change') {
      setInputValue(query);
      return query;
    }
    return inputValue;
  };

Without hooks:

onInputChange = (query, { action }) => {
   if (action === 'input-change') {
      this.setState({ inputValue: query });
      return query;
    }
    return this.state.inputValue;
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Async - React Select
A flexible and beautiful Select Input control for ReactJS with ... Async. Use the Async component to load options from a remote source...
Read more >
react-select-async-paginate - npm
Async function that take next arguments: Current value of search input. Loaded options for current search. Collected additional data e.g. ...
Read more >
How to load React-select Async with initial options for edit item ...
I'm using React-Select's Async Select to implement a dropdown where the user will be able to search through a large amount of data....
Read more >
React Ts React Select Async Paginate - StackBlitz
async function loadOptions(_search: string,. loadedOptions: unknown[]) {. const start = loadedOptions.length; ... options: json.map(item => ({ value: item.
Read more >
Select - Examples - Components - Atlassian Design System
Async creatable. Use AsyncCreatableSelect to allow users to create new options asynchronously. For example, execute async calls before creating the option.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found