user10391869
user10391869

Reputation: 241

react-select onChange not working after change options

I have a component using react-select, I get the options from props, on selct option I want to rerender the select with other options - it works, but onChange not triggered.

import Select from 'react-select';

onChange(option){ 
   dispatch(updateOptions());
}

render(){
  return 
    <Select
      options={this.props.options}
      onChange={this.onChange}
      value={this.state.text}
      menuIsOpen
    />
} 

Upvotes: 7

Views: 22164

Answers (3)

ZebraCoder
ZebraCoder

Reputation: 1700

Try onClick it's working as of now.

Upvotes: 0

Nithish
Nithish

Reputation: 5999

Please have a look at this example, I have created two components one as a Functional Component and the other as Class Component.

Hope this helps.

Upvotes: 3

cuongdevjs
cuongdevjs

Reputation: 731

I was made example and it's working? Let's try it on your code

import React, { Component } from 'react';
import Select from 'react-select';


export default class FixedOptions extends Component {
  state = {
    value: {},
  };

  constructor(props) {
    super(props);
    this.onChange = this.onChange.bind(this);
  }

  onChange(value) {
    console.log(value)
    this.setState({ value: value });
  }

  render() {
    return (
      <Select
        value={this.state.value}
        onChange={this.onChange}
        options={[{a: 1, b: 2}, {a: 2, b: 3}]}
      />
    );
  }
}

Upvotes: 3

Related Questions