On my select element in React, the first couple of selects aren't changing the value, but then they start changing the value to the previous selected option, like if I select the option FRITOS, the value is undefined, then when I select the option COFFEE, the value is FRITOS, and then when I select FRITOS again, the value goes to COFFEE. Really confused what's going on haha.
My function that's setting the state
changeGroup = (event) => {
this.setState({ [event.target.name]: event.target.value });
console.log(this.state.groupSelected);
const bugQuery = {
GroupID: this.state.groupSelected,
};
console.log(bugQuery);
console.log(this.props.bugs);
if (this.state.groupSelected !== undefined) {
this.props.getBugs(bugQuery);
}
};
My select element
<select
style={{ border: "1px solid white", fontSize: "2.7vh" }}
name="groupSelected"
value={this.state.groupSelected}
onChange={this.changeGroup}
>
<option value="FRITOS">FRITOS</option>
<option value="5AFSA">5AFSA</option>
<option selected>Groups</option>
</select>