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

116
Views
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 answers
Answer question

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