I already did all the things but why render is not rendering the option values (that i mean not displayed in the form). Can you suggest me where is the problem? Thanks
My code see below:
// in the constructor
this.state = {
user : {
firstName: "",
lastName: "",
username: "",
email: "",
password: "",
repeatedPassword: "",
telephone: "",
city: "",
zip_code: "",
submitted: false,
userType: {
name:""
},
},
userTypeList: [],
};
fetch
componentDidMount() {
fetch(`http://localhost:8000/api/usertype`, {
method: "GET",
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
}).then(
data => {
return data.json();
}
).then(response => {
this.setState({ [this.userTypeList]: response});
console.log(response);
})
}
in render function
<select
className="custom-select my-1 mr-sm-2"
id="inlineFormCustomSelectPref"
value={this.state.value}
onChange={this.handleChange}
>
<option value="select">Select who you are</option>
{this.state.userTypeList.map(usertype => {
return (
<option value={usertype}>{usertype}</option>
)
})}
</select>