Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Rerender default values. #5

Open
awalkowiak opened this issue Feb 22, 2018 · 3 comments
Open

Rerender default values. #5

awalkowiak opened this issue Feb 22, 2018 · 3 comments

Comments

@awalkowiak
Copy link

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)
@alexandrius
Copy link

Copy classes and add this code to TagSelect.js

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

@rostaingc
Copy link

@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
Copy link

Is there a PR for this?

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

No branches or pull requests

4 participants