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

107
Views
Rellenar el menú desplegable Material de los datos de la llamada Rest

Quiero completar el menú desplegable con datos de Rest API. Intenté esto:

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

Creé este servicio con Axios:

interfaz de exportación CountriesDTO { país?: cadena; código: cadena; }

 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` ); }

No está claro cómo puedo hacer la llamada a la página de React. Intenté esto:

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

¿Cómo puedo completar el menú desplegable con los datos de la llamada GET API?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente llame a su función getData desde useEffect, también debe crear una matriz de estado para almacenar sus datos.

 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 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!