react-filter-box
react-filter-box copied to clipboard
How to change options prop dynamically after load
I have react-filter-box embedded into a component that reads the options dynamically from a database on componentDidMount
.
<ReactFilterBox options={this.state.optionsFromDatabase} />
does reinitialise the options.
@panigrah this should be possible with key
prop, so when you have a new options to load you can change the key value.
Example
class MyComponents extends React.Component {
state = {
key: 1,
options: [],
}
async componentDidMount() {
const newOptions = await getDBData()
this.setState({
key: this.state.key + 1,
options: newOptions
})
}
render() {
return (
<ReactFilterBox options={this.state.optionsFromDatabase} key={this.state.key} />
)
}
}