JedWatson / react-select

The Select Component for React.js
https://react-select.com/
MIT License
27.6k stars 4.12k forks source link

How to point to label and value without change in array? #2068

Closed bogutski closed 4 years ago

bogutski commented 7 years ago

I have array of objects. How to point to label and value without change in array?

    {
      "code": "ALB",
      "alpha2": "AL",
      "name": "Albania",
      "phoneCode": "355"
    },
    {
      "code": "DZA",
      "alpha2": "DZ",
      "name": "Algeria",
      "phoneCode": "213"
    },

No result:

                        <Select
                            name="form-field-name"
                            isLoading={true}
                            options={this.props.listCountries}
                            matchProp="name"
                            valueKey="code"
                        />
stefanoTron commented 6 years ago

try using labelKey instead of matchProp, valueKeyshould be fine

bogutski commented 6 years ago

thank you. I'll try. I used

options={this.props.list.map(option => ({ label: option.displayVal, value: option.val }))}

bladey commented 4 years ago

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues / pull requests.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you feel this issue / pull request is still relevant and you'd like us to review it, please leave a comment and we'll do our best to get back to you.