Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

358
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda