1

I am using react-select lib. I'd like to use addEventListener in my componentDidMount, but unfortunately, when I change, focus, or blur the Select, the window.addEventListener('change'/'focus'/'blur', () => console.log('test')) did not triggered. Is there any work around to make a general listener instead of pass in each Select tag?

Akza
  • 1,033
  • 3
  • 19
  • 37
  • You could check this, possible answer for your question https://stackoverflow.com/questions/36180414/reactjs-add-custom-event-listener-to-component –  Feb 25 '19 at 04:22

1 Answers1

1

React select provides this build in

class SomeComponent extends React.Component {

      onChangeFunc(optionSelected) {
        const name = this.name;
        const value = optionSelected.value;
        const label = optionSelected.label;
      }

      render() {
        return(
          <Select
            name="form-field-name"
            value={val}
            options={options}
            onChange={this.onChangeFunc}
            menuIsOpen={this.onChangeFunc}
            onMenuOpen={this.onChangeFunc}
            onMenuClose={this.onChangeFunc}
          />
        )
      }
    }
Jibin Mathews
  • 1,129
  • 1
  • 10
  • 23