I want to receive requests from 3 different APIs at the same time. I want the enum values returned as a result of the request to be displayed on the select option. Then the user will have to choose from these options. The result of his choice will still be sent to a different API.
function getSeverity() {
return axios.get(`http://localhost:8080/enum/..`);
}
function getCategory() {
return axios.get(`http://localhost:8080/enum/..`);
}
function getStatus() {
return axios.get(`http://localhost:8080/enum/..`);
}
useEffect(() => {
Promise.all([getSeverity(), getCategory(), getStatus()])
.then(function (results) {
const severity = results[0];
const category = results[1];
const status = results[2];
});
}, []);
return (
<div className="container">
<div className="w-75 mx-auto shadow p-5">
<h2 className="text-center mb-4">Add A New Field</h2>
<form onSubmit={e => onSubmit(e)}>
<div className="form-group">
<label>
Severity
</label>
<select defaultValue={severity}>
{_.map(severity, (value, key) => (
<option value={key} key={key}>{value}</option> ))}
</select>
</div>
<div className="form-group">
<label>
Status
</label>
<input
type="text"
className="form-control form-control-lg"
placeholder="Enter status"
name="status"
value={status}
onChange={e => onInputChange(e)} />
</div>
<div className="form-group">
<label>
Category
</label>
<input
type="text"
className="form-control form-control-lg"
placeholder="Enter category"
name="category"
value={category}
onChange={e => onInputChange(e)}
/>
</div>
</form>
</div>
</div>
);
};
You can loop through the object keys using Object.keys
Your loop will look like this.
{Object.keys(severity).map(key => (
<option value={key} key={key}>{serverity[key]}</option> ))}
You'll get the keys in an array and using .map you can loop over it.