Skip to content

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

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

Open
dewabagas opened this issue Dec 18, 2018 · 4 comments
Open

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

dewabagas opened this issue Dec 18, 2018 · 4 comments

Comments

@dewabagas
Copy link

image

@dewabagas
Copy link
Author

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

@SSTPIERRE2
Copy link

SSTPIERRE2 commented Nov 1, 2019

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

svvitale commented Feb 4, 2020

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

nmhung commented Sep 18, 2020

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.

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