'conditionally disable an option using react select not work when change option props passed to the Select
I'm trying to conditionally make an option of a select disabled, for example, if two items are selected, the the third option is diabled, if one or three items are selected, the third option is enabled. However the Select option does not change when selected number of items change even it's passed as props of the option. When I console.log, I do see the option object disabled value changed when I change selected items numbers. May I know why the Select does not re render? Thanks!
class parentComponent extends PureComponent{
constructor(props) {
super(props)
this.state = {
options:[]
}
}
render() {
const {
countOfItems
} = this.props
let options = [...somefunction()];
if (somecondition1) {
options.options.filter(...)
}
if (somecondition2) {
options.options.filter(...)
}
this.setState({options})
......
if (countOfItems === 2) {
options[3].disabled = true
} else {
options[3].disabled = false
}
console.log(options[3])
......
return (
<Select
options ={options}
isOptionDisabled = {(option) => option.disabled}
......
)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
