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

issue with resetting to default index, select is not a function #207

Open dewabagas opened 5 years ago

dewabagas commented 5 years ago

image

dewabagas commented 5 years ago

whenever i'm trying to reset the value , it's always goes like this,. i don't know why, i've tried everything,

SSTPIERRE2 commented 5 years ago

I'm having the same issue. The readme says there are 3 exposed methods but I see no such methods in the code, they don't exist. @sohobloo

svvitale commented 4 years ago

You can achieve this using refs:

class MyComponent extends Component {
  constructor(props) {
    super(props);
    this.dropdownRef = React.createRef();
  }

  componentDidMount() {
    const { value, options } = this.props;
    const selectedIdx = (options || []).findIndex(option => option === value);

    this.dropdownRef.current.select(selectedIdx);
  }

  render() {
    const { options } = this.props;

    return (
      <ModalDropdown ref={this.dropdownRef} options={options} />
    );
  }
}
nmhung commented 4 years ago

You can achieve this using refs:

class MyComponent extends Component {
  constructor(props) {
    super(props);
    this.dropdownRef = React.createRef();
  }

  componentDidMount() {
    const { value, options } = this.props;
    const selectedIdx = (options || []).findIndex(option => option === value);

    this.dropdownRef.current.select(selectedIdx);
  }

  render() {
    const { options } = this.props;

    return (
      <ModalDropdown ref={this.dropdownRef} options={options} />
    );
  }
}

thank you so much. it works for me.