我想创建一个反应选择下拉列表,但是我不知道如何将选项与列表对象绑定。错误消息:“ TypeError:options.reduce不是函数...”下面是我的代码:
myDropdown.js
import React, {Component} from 'react';
import axios from 'axios';
import Select from 'react-select';
class myDropdown extends Component{
state={List:{value:'',label:''} };
//call api to get data
getLists= ()=>{
axios.get('myapiurl')
.then(response=>{
this.setState(prevState => ({
List: { // object that we want to update
...prevState.List, // keep all other key-value pairs
value: prevState.List.SUBJECT,
label: prevState.List.CATEGORY
}
}))
});
};
componentDidMount(){
this.getLists();
}
//render dropdown
render(){
return(
<Select value={this.props.value} onChange={this.props.onChange} options={this.state.List} />
);
}
}
export default myDropdown;