Disable opt-groups feature in React-Select V2

Viewed 226

I was populating v1 with a data structure like:

[{"label":"email","resource_type":"Email","options":[{"label":"Desc","value":1}]},{"label":"survey","options":[{"label":"HXH","value":3}]

And then populating another select with nested options. But now v2 auto populates the select with opt groups because of the nested option key of my json. How do I disable that?

1 Answers

There doesn't seem to be anything in react-select to disable the grouping but you could map your options before passing them into react-select so that it only includes the relevant data.

const originalOptions = [
  { label: 'email', resource_type: 'Email', options: [{ label: 'Desc', value: 1 }] },
  { label: 'survey', options: [{ label: 'HXH', value: 3 }] },
];

<Select
  options={originalOptions.map(option => {
    return { label: option.label, value: option.value };
  })}
/>

Related