I read a json file in the first select box and set the value as state and i don't know how to read that value to another select box. All I get is the whole array as one string.
This is the code where i set state as an object from the first select box:
constructor(props) {
super(props);
this.state = {
selectedCourse: {}
};
this.onSelectCourse = this.onSelectCourse.bind(this);
}
onSelectCourse(e) {
console.log(e.target);
this.setState(
{
selectedCourse: {
...this.state.selectedCourse,
[e.target.id]: [e.target.value]
}
},
() => {
console.log(this.state);
}
);
}
render() {
const { selectedCourse } = this.state;
This is the first select box:
<select onChange={this.onSelectCourse}>{CoursesList.courses.map((item, i) =><option key={i} value={item.dates}>{item.name}</option>)}</select>
This is the select box where i want to display the data from state object array:
<select>{Object.entries(this.state.selectedCourse).map((item) =><option key={item}>{item}</option>)}</select>