Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Select: Multiple values in defaultValue attribute

Im trying to add multiple values inside my defaultValue attribute but without success.

<Select 
   value={this.state.selectedTests} 
   defaultValue={this.getDefaultValues(this.props.tests)} 
   isMulti onChange={(e) => this.handleChange(e)} 
   options={this.state.allTests} 
   className="basic-multi-select dropDownSelector"
 />

getDefaultValues() returns an array:

0:{value: "t1", label:"Test1"}
1:{value: "t2", label:"Test2"}

But the Select element shows no labels...

Anyone else faced the same issue or knows how to solve this?

Thank you for your help!

like image 786
MagD Avatar asked Dec 08 '25 19:12

MagD


1 Answers

I solved my problem :) The values in the attribute "value" overwrote the values in the attribute "defaultValue". I delete the attribute "value" and it works now.

Changed code:

<Select 
   defaultValue={this.getDefaultValues(this.props.tests)} 
   isMulti onChange={(e) => this.handleChange(e)} 
   options={this.state.allTests} 
   className="basic-multi-select dropDownSelector"
 />
like image 85
MagD Avatar answered Dec 11 '25 10:12

MagD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!