react-native-tag-select icon indicating copy to clipboard operation
react-native-tag-select copied to clipboard

Rerender default values.

Open awalkowiak opened this issue 7 years ago • 3 comments

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)

awalkowiak avatar Feb 22 '18 11:02 awalkowiak

Copy classes and add this code to TagSelect.js

componentDidUpdate(prevProps, prevState, prevContext) {
    if (prevProps !== this.props) {
        this.updateState();
    }
}

alexandrius avatar Sep 26 '18 12:09 alexandrius

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

    }

}

rostaingc avatar Feb 17 '19 09:02 rostaingc

Is there a PR for this?

ashishmusale avatar May 03 '19 13:05 ashishmusale