class App extends Component {
//функция фильтрации
isOptionDisabled(arr) {
console.log("arr", arr);
arr.forEach((val, i, dis) => {
return option => {
console.log("option", option, dis); //не выводит в консоль
return option.value !== val;
};
});
}
render() {
//массив всех объектов для опций
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" }
];
//массив для фильтрации
const disOptions = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" }
];
return (
<Select
options={options}
isOptionDisabled={this.isOptionDisabled(disOptions)}
/>
);
}
}
class App extends Component {
state = {
options: [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry", isDisabled: true },
{ value: "vanilla", label: "Vanilla" },
],
}
render() {
return (
<Select
options={this.state.options}
/>
);
}
}
class App extends Component {
state = {
options: [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" }
],
disabled: [ 'chocolate', 'vanilla' ],
}
isOptionDisabled = option => this.state.disabled.includes(option.value)
render() {
return (
<Select
options={this.state.options}
isOptionDisabled={this.isOptionDisabled}
/>
);
}
}
createIsOptionDisabled = disOptions => option =>
disOptions.some(({ value }) => value === option.value);
return (
<Select
options={options}
isOptionDisabled={this.createIsOptionDisabled(disOptions)}
/>
);