I am receiving this json Response From API.
{
"1": "Suits",
"2": "Sarees",
"3": "Footmats",
"4": "Carpets",
"5": "Sofa Covers"
}
I want to take this json and display it in a drop down using formik
// Setting State
state = {
itemType: {
key: 0,
value: 'Select'
}
}
// Calling API in component did mount
componentDidMount() {
axios.get('/itemTypes')
.then(response => {
this.setState({
itemType: response.data
});
this.createItemType();
}).catch(error => {
console.log(error);
});
}
// filling options values for drop down
createItemType = () => {
let items = [];
for (const [key, value] of Object.entries(this.state.itemType)) {
items.push(<option key={key} value={key}>{value}</option>);
//here I will be creating my options dynamically
}
return items;
}
// I have this field component to create drop down in <Formik> <Form> tag.
<Field name="itemType" className="form-control" component="select" placeholder="Item Type">
{this.createItemType}
</Field>
My aim is to create dynamic values drop down like this
What I am getting on screen is

No drop down, only values gets printed.
Any help will be appriciated
