我使用的是react-select lib。我想在我的componentDidMount中使用addEventListener,但不幸的是,当我change、focus或blur Select时,window.addEventListener('change'/'focus'/'blur', () => console.log('test'))没有触发。有没有什么办法可以做一个通用的侦听器来代替传递每个Select标记?
发布于 2019-02-25 13:52:29
React select提供了此内建功能
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}
/>
)
}
}https://stackoverflow.com/questions/54859116
复制相似问题