[V2] Setting initial value of select component with a string value no longer works
See original GitHub issueMaybe I’m missing something, but from what I can tell the way that used to work to set the initial value of the select component does not work anymore in version 2.0. Here’s what used to work (simplified for readability):
<ReactSelect
value={field.value}
options={field.options.map((option) => ({
...option,
label: option.name,
value: option.name,
clearableValue: true
}))}
/>
In the above example the field.value
was a string value coming back from the server that matched the name of one of the options.
Is it no longer possible to set the initial value (and all subsequent values) with a string? That was a very nice feature and I would like to make a request for it to make a comeback if it’s no longer available. If it’s still there, can someone show me the light? I can’t seem to get it working with v2.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:23 (5 by maintainers)
Top Results From Across the Web
Setting a default value with react-select not working
I have a simple React component which gets an ...
Read more >How to set default value in select using ReactJS
Following are the two approaches to set default value in select using ReactJS: Approach 1: Without using React Select component.
Read more >Form Input Bindings - Vue.js
v-model will ignore the initial value , checked or selected attributes found on any form elements. It will always treat the current bound...
Read more >ASP.NET Core Blazor data binding - Microsoft Learn
There's no sensible way to represent a <select> element option value as a C# object null value, because: HTML attributes can't have null...
Read more >Form Select | Components - BootstrapVue
options can be an array of strings or objects, or a key-value object. ... Only basic/native HTML is supported in the html field...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just spent two hours debugging just to realize this was the issue. This is not even mentioned in the upgrade guide! I stumbled upon this only when I saw this
type ValueType = OptionType | OptionsType | null | void
in the reference.I don’t understand why do you need an additional wrapper. Having an array with objects having
label
andvalue
keys can be easily returned as string with the current version 2, without any additional component:Doing it this way, in
this.state.value
we’ll have the string (or number, or whichever value you have selected), instead of the entire object.Edit: Please note that I’ve used
label
andvalue
, as it’s the default used by react-select, and also it’s the one exemplified in the package linked by @jossmac. But you can use this approach for any kind of array if I’m not wrong.