I am using react-select and the creatable function that allows you to create a new select option - just type in the select/input field on example. When you type in the first custom option it defaults into a group called "new Group". When you create a 2nd custom option this should overwrite the first in the new group. However the group name disappears.
This is the incorrect code that results in that behavior...
if (this.state.hasCreatedOption) {
options[this.state.hasCreatedOption] = newOption;
} else {
options.map(option => {
if (option.label === "New group") {
return {
label: option.label,
options: option.options.push(newOption)
};
}
return option;
});
}
hasCreatedOption = options.length - 1;
Here is the example created - https://codesandbox.io/s/w761j8v855