'React-Select is not showing selected options on the searchbar
When I try and select an option from the dropdown it doesn't show on the searchbar if I add an if statement inside the onChange handler function, when I remove "if statement" the selected options get displayed on the bar.
<Select
isMulti
name="colors"
options={cat.subs.map((sub) => {
return { value: sub, label: sub.name };
})}
className="basic-multi-select"
classNamePrefix="select"
onChange={handleChange}
/>
And this is the change handler function, it works perfectly, but the selected option are not displayed on the searchbar
const handleChange = (newValue, actionMeta) => {
if (actionMeta.action === "remove-value") {
removeSubCategory(actionMeta.removedValue.value);
} else if (actionMeta.action === "select-option") {
addSubCategory(actionMeta.option.value);
}
};
Solution 1:[1]
If the removeSubCategory function removes the value from your data, it won't be available to select again, will it? Please can you provide more context on how those functions modify the data that provides your options.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Baba Ali |
