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 isn't using the options passed

See original GitHub issue

I can’t have an actual example because the API I’m using isn’t public, but I’ve simplified the code as much as I could. Basically, the options I pass to the getOptions callback isn’t always showing properly in the select. My api returns a maximum of 5 items, e.g:

  • Pitt st would render 5 items in the select
  • Pitt st ma would render 1 items in the select even though the console.log before the callback has 5 items. To properly show those items, I have to close the dropdown and open it again. I tried with cache={false} & complete: false/true (yeah, both) and every possible combination but it didn’t change anything.

Am I doing anything wrong or it’s expected since it’s in rc ?

Cheers

import React, { Component, PropTypes } from 'react'
import Select from 'react-select'

let timeout
const getOptions = (text, cb) => {
  if (text.length <= 3) return cb()

  if (timeout) clearTimeout(timeout)
  timeout = setTimeout(() => {
    fetch(`api/${text}.json`)
      .then((res) => res.json())
      .then((data) => {
        const options = data.map((d) => ({
          value: d,
          label: d.label,
        }))

        console.log(options)
        cb(null, { options })
      })
  }, 500)
}

export default ({ value, onChange }) => (
  <Select.Async
    value={value}
    loadOptions={this.getOptions}
    onChange={onChange()}
  />
)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
bvaughncommented, Sep 13, 2016

Ah. If you just want to disable filtering and let the Api handle it- then just provide your own filterOptions function that returns the full options array every time. 😄

function filterOptions(options) {
  return options;
}
2reactions
Calveincommented, Sep 13, 2016

I forgot to add cb when I simplified the example, but I do have it in my actual code.

Here’s screenshots of the weird behavior I’m experiencing:

  • Type pitt st
  • The console logs 5 items, the dropdown show 5 items image
  • Without leaving the input, add mall to the search
  • The console logs 5 items, the dropdown shows nothing image
  • Click out of the input and back in
  • The dropdown shows the 5 items it previously didn’t show image
Read more comments on GitHub >

github_iconTop Results From Across the Web

React-select/async not showing options to filter - Stack Overflow
AsyncSelect is a react library that you can use to select a specific value from the database its a select option HTML but...
Read more >
Async Data Fetching with React-Select - OpenReplay Blog
With it, we will demonstrate different select options such as singe, multi-search, and creatable search in which users can create ...
Read more >
API - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
How to Asynchronously Populate List Options in the ... - Sanity.io
Let's use our schema's options to pass in a url and a handler , as well as change some of the names of...
Read more >
Asyncify — Emscripten 3.1.26-git (dev) documentation
Asyncify lets synchronous C or C++ code interact with asynchronous JavaScript. ... use the Module.ccall function and pass async: true to its call...
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