sohobloo / react-native-modal-dropdown

A react-native dropdown/picker/selector component for both Android & iOS.
MIT License
1.19k stars 477 forks source link

defaultValue doesn't update after rendering the first time #181

Open eddietex opened 6 years ago

eddietex commented 6 years ago

I'm setting the defaultValue and defaultIndex props like this:

defaultIndex={this.state.defaultIndex}
defaultValue={this.state.defaultValue}

and the initial states like so:

defaultIndex: -1,
defaultValue: 'Touch to Select'

And at some point, when some data is feetched, the states are updated. When this happens, defaultIndex is updated properly according to the component's state, but for some reason the defaultValue doesn't change when the component gets re-rendered, only when onSelect is triggered.

If you see the image below, the orange color is the style of a selected item, and even though the defaultIndex was updated, the defaultValue is still the same as it was when it was first rendered. screen shot 2018-07-09 at 6 57 09 pm

vonwao commented 5 years ago

I'm still having this issue. Workarounds?

winseyli commented 5 years ago

You can add the following to ModalDropdown

  componentDidUpdate(prevProps, prevState) {
    if (this.props.defaultValue !== prevProps.defaultValue) {
      this.setState({buttonText: this.props.defaultValue})
    }
  }
Subway19 commented 4 years ago

This is still an issue. Component doesn't update on change of props, no ComponentDidUpdate in source code. Please re-check