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.

Select.Async not working correctly from 1.0.0-rc.6 onwards

See original GitHub issue

I have a basic select set up as follows which works perfectly fine on 1.0.0-rc.5 but once I update to rc.6 onwards, it causes an issue where for example search say sydney it will provide a list of options however upon selecting a option it is not shown in the Select input field despite the suburb value being correctly returned from onChange. I have had a look into the Async.js code and from what I’ve gathered (not 100% sure) it appears to be that upon selecting an option, the inputValue field gets set to “” and causes the Async this.state.options field to become [] and therefore the value has nothing to match against. So not sure if there is a bug or I need to now change something in my implementation for Select.Async. Any help would be much appreciated. render:

 <Select.Async
                loadOptions={handleGetGoogleSuburbs}
                onChange={handleSuburbSelect}
                value={suburb}
 />

handlers:

handleGetGoogleSuburbs(input: string, optionsCallBack: any) {
    getAutoSuggestions(input)
      .then(predictions => {
        const options = predictions.map(x => {
          return { value: x.place_id, label: x.description };
        });
        optionsCallBack(null, { options });
      })
      .catch(() => {
        this.predictions = [];
        optionsCallBack(null, { options: [] });
      });
  }

handleSuburbSelect(selectRes: { value: string; label: string }) {
    if (!selectRes) {
      this.setState({ suburb: "" });
      return;
    }

    this.setState({
      suburb: selectRes.value
    });
  }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jscheidcommented, Sep 28, 2017

This will also make your code much simpler

I can tell you have good intentions with this change, but I fail to see how this is an improvement.

I don’t want to store the whole option, all that matters is the value anyway. The label is just that, a label. This is also different from how normal HTML5 <select> tag works.

I now have to keep extra state for this. My store just deals in plain values, so now I have to keep the whole option in this.state to make Select.Async happy and keep that state in sync with store’s value, it’s really messy.

Or I need to access async loaded options to search for my value, but I believe that would have to use internal APIs? Or I need to couple the select component to the async load function more tightly so that I can access the options loaded so far. None of these feel right.

Would you reconsider this change? Or at least make it so that I can pass in just { value: value } with no label or a dummy label and it will work ok?

1reaction
acordiner92commented, Sep 29, 2017

@agirton @bickle66 Thanks for the update! Will update my accordingly

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Select Async loadOptions is not loading options properly
Here is my front end code for react-async select component. I do use debounce in my getOptions function to reduce number of backend...
Read more >
async function expression - JavaScript - MDN Web Docs
The async function keywords can be used to define an async function inside an expression.
Read more >
Iterating Asynchronously: How to use async & await ... - Medium
In this post, we will look at how we go about iterating using a foreach loop asynchronously. Now you may be thinking why...
Read more >
Redux Fundamentals, Part 6: Async Logic and Data Fetching
dispatch function, this also means that we could actually pass something that isn't a plain action object to dispatch , as long as...
Read more >
How To Create Searchable, Async Dropdowns with React ...
An introduction to React Select v2, a sleek, modern dropdown component for React. ... Fix any errors or issues with your project, ...
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