Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderButtonText renders '[object Object]' if there is a call to setState in onSelect or renderButtonText functions #139

Closed
Culzean opened this issue Feb 22, 2018 · 7 comments

Comments

@Culzean
Copy link

Culzean commented Feb 22, 2018

I have version 0.6.1 and am using a slightly more complex data structure.

         <ModalDropdown
              dropdownStyle={styles.pickerItemStyle}
              style={styles.dropDwon}
              textStyle = {styles.DropDownText}
              dropdownTextStyle = {styles.DropDownPickerText}
              renderButtonText = { (rowData) => {
                this.setState({selectedService: rowData.ssid});
                return rowData.ssid;
                } }
              defaultValue = {"Please select wifi"}
              options = {this.state.services}
              renderRow = {this._renderDropdownRow.bind(this)}
              onSelect = {this.pickerOnSelect.bind(this)}
            >
         </ModalDropdown>

If there is a call to setState for both of these functions then the dropdown text renders as [object Object]. If I remove the call then the dropdown renders the ssid strings as expected.

@Culzean
Copy link
Author

Culzean commented Feb 23, 2018

it seems any call to setState is breaking the renderButtonText. [object Object] looks very broken.

@brascene
Copy link

@Culzean the same here, if I use setState it goes in some endless loop and I receive maximum call stack size exceeded error.

@mtimofiiv
Copy link

Having the same issue as well, and I am not using any this.setState in it either. Here's a snippet:

<ModalDropdown
  ref={self => { this.accountPicker = self }}
  defaultValue={i18n.t('ui.inputs.account_picker.placeholder')}
  options={accounts.data}
  onSelect={({ address }) => this.updateTxField({ from: address })}
  renderRow={({ title }) => <Text>{title}</Text>}
  renderButtonText={({ title }) => title}
  style={style.dropdownContainer}
  textStyle={style.dropdownText}
  dropdownStyle={style.dropdownStyle}
/>

In my example, accounts.data is an array of objects with obviously 2 props, title and address.

The results are as follows (image 1 is during selection, 2 is after the option is clicked):

screen shot 2018-03-06 at 14 42 12

screen shot 2018-03-06 at 14 42 21

I tried reverting back to version 0.5.0 to see what would happen and in that, [Object object] shows up all the time, not just after selection.

@mtimofiiv
Copy link

mtimofiiv commented Mar 6, 2018

I tracked it down. The error occurs in componentWillReceiveProps:

  componentWillReceiveProps(nextProps) {
    let {buttonText, selectedIndex} = this.state;
    const {defaultIndex, defaultValue, options} = nextProps;

    buttonText = this._nextValue == null ? buttonText : this._nextValue.toString(); //<<< here
    selectedIndex = this._nextIndex == null ? selectedIndex : this._nextIndex;
    if (selectedIndex < 0) {
      selectedIndex = defaultIndex;
      if (selectedIndex < 0) {
        buttonText = defaultValue;
      }
    }
    this._nextValue = null;
    this._nextIndex = null;

    this.setState({
      loading: !options,
      buttonText,
      selectedIndex
    });
  }

mtimofiiv added a commit to mtimofiiv/react-native-modal-dropdown that referenced this issue Mar 6, 2018
@mtimofiiv
Copy link

mtimofiiv commented Mar 6, 2018

I submitted a PR -> #142

Feel free to use mtimofiiv/react-native-modal-dropdown while this is awaiting review. It fixes the issue for me.

@sohobloo
Copy link
Owner

sohobloo commented Mar 9, 2018

Fixed in v0.6.2 #146

@Culzean
Copy link
Author

Culzean commented Jul 19, 2018

Just testing out the update now. Issue resolved. Thanks!

@Culzean Culzean closed this as completed Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants