Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

349
Views
How can I show enum values ​from API in select dropdown in reactjs?

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>
  );
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!