Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change options prop dynamically after load #26

Open
panigrah opened this issue Jan 11, 2020 · 1 comment
Open

How to change options prop dynamically after load #26

panigrah opened this issue Jan 11, 2020 · 1 comment

Comments

@panigrah
Copy link

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.

@lakhansamani
Copy link

@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} />
  )
 }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants