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 with getOptionValue

See original GitHub issue

I’d like to use React Select library so that a user could select one option. API server stores available options. API request argument is a prefix and the server responses with a list of options (array of strings) matching the given prefix.

So I’m using Async component. Because the server responses with an array of strings, I define component’s props getOptionValue and getOptionLabel as {d => d}.

Labels in the menu are shown as expected, but the problem is that when I select some option, the menu just closes and no option seems to be selected.

You can see this behavior in https://codesandbox.io/s/reactcodesandboxerexample-j1xxh , code is in file example.js. API request is replaced by creating Promise.

I tried to map fetched options to objects with properties value and label so that I don’t have to override getOptionValue and getOptionLabel, but this mapping takes a huge amount of time (several seconds), because number of fetched options may be in thousands.

Does anybody have an idea how could I fix this buggy behavior in React Select, so that I could see the selected option?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

2reactions
Klinton90commented, Sep 11, 2019

I think, we need better documentation explaining how getOptionValue is used. I just tested couple scenarios with Select and list of objects as options:

  • defaultValue - needs to be an object in order to find and select option in list. I expected (at least other libraries work that way): in order to preselect value each option is compared as defaultValue === getOptionValue(option)
  • value - same logic - always needs to be an object, instead of some property…

My usecase:

  • options is list of Objects (e.g. Author in format {id: number, name: string})
  • I need to select Authors for the Book. Book is {id: number, name: string, authorIds: number[]}
0reactions
ebonowcommented, Jan 8, 2021

In an effort to close out stale issues, I will be closing this. Please feel free to reply if you have any concerns or questinos and this can be reopened if necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make react-select 2.0.0 <Async> work with redux-form <Field>
My select box can show all options correctly, but redux form won't pick up the value, with the warning: Warning: A component is...
Read more >
Advanced - React Select
React Select. A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete, async and creatable support. Star.
Read more >
Implementing react-select Async with React Hooks and ...
This tutorial is about implementing the React Component react-select with Async AJAX request and pagination applied.
Read more >
org.apache.commons.cli.CommandLine.getOptionValue java ...
Parses the input args with a command line format, using * {@link org.apache.commons.cli.CommandLineParser}. * * @param args the input args * @return true...
Read more >
React-Select Async loadOptions is not loading options ...
Coding example for the question React-Select Async loadOptions is not loading ... handleInputChange.bind(this); } getOptionValue = (option) => option.id; ...
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