Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

114
Vistas
Populate Material dropdow menu from Rest call data

I want to populate dropdown menu with data from Rest API. I tried this:

<Select id="country-helper">
{array.map((element) => (
     <MenuItem value={element.code}>{element.country}</MenuItem>
       ))}
</Select>

I created this service with Axios:

export interface CountriesDTO { country?: string; code: string; }

import axios, { AxiosResponse } from "axios";
import { CountriesDTO } from "./types";

const baseUrl = "http://localhost:8080/api";

export async function getCountries(): Promise<AxiosResponse<CountriesDTO[]>> {
  return await axios.get<CountriesDTO[]>(
    `${baseUrl}/merchants/onboarding/countries`
  );
}

It's not clear how I can make the call into the React page. I tried this:

useEffect(() => {
        const getData = async () => {
            getCountries()
                .then((resp) => {
                    console.log(resp.data);
                })
                .catch((error) => {
                    console.error(error);
                });
        };

    }, []);

How I can populate the dropdown using the data from GET API call?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just call your function getData from useEffect, you should also create state array to store your data.

const [array, setArray] = useState<CountriesDTO[]>([]); // <=== create state array

useEffect(() => {
  getData(); // <=== call your function
}, []);

const getData = async () => {
  getCountries()
    .then((resp) => {
      setArray(resp.data);
    })
    .catch((error) => {
      console.error(error);
    });
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda