score:11

Accepted answer

here the issue is not with state selection, the actual issue is that the label is not getting displayed.

so, as per your addisyoungervalue function you are setting the value of this.state.currentobject.isyounger to whole object. i.e. { value: true, label: "younger" }. so, the issue can be solved by changing the value of initial state by below.

this.state = {
      array: [],
      currentobject: {
        isyounger: { value: true, label: "younger" }
      }
    };

and hurrey, the default value label will be shown..

score:5

there is an alternate way to use value as your defaultvalue. in my case i have used "id" and "industry" instead of "label" and "value"

this.state = {
     interested_industries: [{id:"any", industry:"any"}]
}

and in select component:-

<select 
    name="interested_industries"
    options={industries}
    value={interested_industries}
    getoptionlabel={ x => x.id}
    getoptionvalue={ x => x.industry}
    onchange={this.handleselect}
    ismulti
/>

score:6

your defaultvalue or value must be objects. in your case like this:

defaultvalue={isyoungeroptions[0]}

or

this.state = {
   array: [],
   currentobject: {
     isyounger: { value: "true", label: "younger" }
   }
 };

here an live example.


Related Query

More Query from same tag