rafaelmotta / react-native-tag-select

🏷 A simple tag component to act as radio button / checkbox
156 stars 43 forks source link

Rerender default values. #5

Open awalkowiak opened 6 years ago

awalkowiak commented 6 years ago

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:

alexandrius commented 5 years ago

Copy classes and add this code to TagSelect.js

componentDidUpdate(prevProps, prevState, prevContext) {
    if (prevProps !== this.props) {
        this.updateState();
    }
}
rostaingc commented 5 years ago

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

    }

}
ashishmusale commented 5 years ago

Is there a PR for this?