react-native-tag-select
react-native-tag-select copied to clipboard
Rerender default values.
Could you consider adding rerendering after default values change? Right now default values are set before render (in componentWillMount). It would be nice to have possibility to rerender default values (probably componentWillUpdate should be enough here) Possible use-cases:
- setting selected values basing on other data selected by user,
- downloading selected tag data from server (this is my case, now i have to wait until all data is fetched and then i can render rn-tag-select)
Copy classes and add this code to TagSelect.js
componentDidUpdate(prevProps, prevState, prevContext) {
if (prevProps !== this.props) {
this.updateState();
}
}
@alexandrius 's code was raising alerts as updateState was non defined. This did the trick for me:
componentDidUpdate (prevProps, prevState, prevContext) {
if (prevProps !== this.props) {
const value = {}
this.props.value.forEach((val) => {
value[val[[this.props.keyAttr]] || val] = val
})
this.setState({ value })
}
}
Is there a PR for this?