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.

What is the point of getOptionValue prop ?

See original GitHub issue

Hi,

The documented getOptionValue prop does not seem to have any effect. Related to #2920

Using these options :

const options = [{ id: 'one', label 'One' }, { id: 'two', label: 'Two' }]

<Select
    options={options}
    getOptionValue={option => option.id}
/>

getOptionValue does not seem to do anything :

  • In the onChange event handler, the value is still the option object
  • passing a string id (example: ‘one’) as value does not select the correct option
  • worth, passing an object like { id: 'one' } as value does not select the correct option

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
hugomalletcommented, Jan 30, 2019

Thank you @Rall3n, it now makes sense ! This should be documented because it’s really confusing

1reaction
richard-ejemcommented, Apr 16, 2021

@Rall3n thanks for explanation. In this case, shouldn’t you consider adding some warning when user provides any option without {value: string} ? As I said, the only error I got was from React complaining about null in input[value] and it needed some research to find out that I should use getOptionValue. And from what you say, it seems that react-select would become glitchy also in a bunch of other ways when someone doesn’t use {value: string}, although it seems to be supported at first sight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-select change name of option fields from ({ value: '', label ...
Use getOptionLabel and getOptionValue props. <Select getOptionLabel={option => option.name} getOptionValue={option => option.id} ...
Read more >
Advanced - React Select
React Select exposes a variety of eventListeners to you via props. The onchange function prop now has the following signature.
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 >
How to Get Selected Value from a Mapped Select Input in React
... can be a little tricky as you need to think from a data point of view ... Assign the value property from...
Read more >
CommandLine (Apache Commons CLI 1.5.0 API)
Gets an array of the processed Option s. String · getOptionValue(char opt). Retrieve the first argument, if any, of this 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