react-native-modal-dropdown icon indicating copy to clipboard operation
react-native-modal-dropdown copied to clipboard

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

Open dewabagas opened this issue 7 years ago • 4 comments

image

dewabagas avatar Dec 18 '18 13:12 dewabagas

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

dewabagas avatar Dec 18 '18 13:12 dewabagas

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

SSTPIERRE2 avatar Nov 01 '19 15:11 SSTPIERRE2

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} />
    );
  }
}

svvitale avatar Feb 04 '20 22:02 svvitale

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.

nmhung avatar Sep 18 '20 08:09 nmhung