How to fetch api data from mysql to dropdown list in React Native?

Hi, I’m making a form and I need to load data in a dropdownlist and select it, but I don’t know how to do it and I can’t find examples, except those that have a json file with all the data.
I can insert my data with success but I need a dropdownlist for other important data.

My form:


import React from 'react';

import {
  View,
  StyleSheet,
  TextInput,
  ScrollView,
  Text,
  TouchableOpacity,
  TouchableHighlight,
} from 'react-native';

import Modal from 'react-native-modal';
import { useState } from 'react';
import Icon from 'react-native-vector-icons/FontAwesome';
import { Dropdown } from 'react-native-material-dropdown';

export default class RegistroScreen extends React.Component {

  constructor(props)
  {
    super(props);
    this.state=({nombre:'',apellidos:'',alias:'',nro_cedula:'',correo:'',passwd:'',passwd2:'',celular:''});
    //this.state=({nacionalidad:[]})
  }

  componentWillMount(){
    this.getdata();
  }

  getdata(){
    var temp = [];
    fetch("localhost:8080/", {
      method: "Get",
      headers: {
          Accept: "application/json",
          "Content-Type": "aplication/json"
      }  
    })
  }

  InsertRecord=()=>
  {
    var nombre=this.state.nombre;
    var apellidos=this.state.apellidos;
    var alias=this.state.alias;
    var nro_cedula=this.state.nro_cedula;
    var correo=this.state.correo;
    var passwd=this.state.passwd;
    var passwd2=this.state.passwd2;
    var celular=this.state.celular;

    if(nombre.length==0 || apellidos.length==0 || nro_cedula.length==0 || correo.length==0 || passwd.length==0 || passwd2.length==0 || celular.length==0)
    {
      alert("Le faltan campos por llenar");
    }else{
      var InsertAPIURL="http://10.0.2.2:80/api/insert.php";
      var headers={
        'Accept':'application/json',
        'Content-Type':'application/json',
      };
      var Data={
        nombre: nombre,
        apellidos: apellidos,
        alias: alias,
        nro_cedula: nro_cedula,
        correo: correo,
        passwd: passwd,
        passwd2: passwd2,
        celular: celular,
      };
      fetch(InsertAPIURL,
          {
            method:'POST',
            headers:headers,
            body: JSON.stringify(Data),
          }
      ).then((response)=>response.json())
        .then((response)=>
        {
          alert("Registro realizado con éxito");
          {/* SCREEN LOGIN */}
          this.props.navigation.navigate('Login');
          // value('cedula') = '';
        })
        .catch((error)=>
        {
          alert("Error"+error);
        }      
      )
    }
  }
  render() {

    return (
      <ScrollView style={styles.container}>
            <View style={{flex: 1, flexDirection: 'column'}}>
                <Dropdown 
                  label="Nacionalidad"
                  onChangeText={this.onChangeText}
                  //data={this.state.nacionalidadListData}
                />
            <View style={{flex: 4, flexDirection: 'column'}}>
            
                <View style={{flex: 0.5}}>
                  <TouchableOpacity
                  style={styles.submitButton}
                  onPress={this.InsertRecord}
                  >
                    <Text style={styles.submitButtonText}> Enviar </Text>
                  </TouchableOpacity>
                </View>
            </View>
      </ScrollView>
    );
  }

My insert API file:


<?php

    $MW = mysqli_connect("localhost","root","");
    $DB = mysqli_select_db($MW,"MapamundiWorld");
    $EncodedData = file_get_contents('php://input');
    $DecodedData = json_decode($EncodedData,true);

    $nombre = $DecodedData['nombre'];
    $apellidos = $DecodedData['apellidos'];
    $alias = $DecodedData['alias'];
    // $nacionalidadID = $_POST['nacionalidadID'];
    $nro_cedula = $DecodedData['nro_cedula'];
    $correo = $DecodedData['correo'];

    $passwd = $DecodedData['passwd'];

    $passwd2 = $DecodedData['passwd2'];
    $celular = $DecodedData['celular'];

    $IQ = "insert into usuario(nombre,apellidos,alias,nro_cedula,correo,passwd,passwd2,celular) values ('$nombre','$apellidos','$alias','$nro_cedula','$correo','$passwd','$passwd2','$celular')";

    $R = mysqli_query($MW,$IQ);
    if($R){
        $Message="Su usuario ha sido registrado satisfactoriamente :D ";
    }else{
        $Message="Error, intente más tarde";
    }

    $Response[]=array("Usuario"=>$Message);
    echo json_encode($Response);

?>

Please help :frowning: Thanks

Hi, I’m Jess from the Expo team. This comment - even if ( / especially because) vaguely and broadly at your forum companions - is entirely inappropriate.

I will be suspending your account; please email me at secure [ at ] expo [ dot ] dev if you’d like to discuss whether and when we reinstate your access.

Using the inbuilt Fetch API. Data fetching on mount.
Using Axios. Fetching with Axios.
Fetching data with Apisauce.
Using render props to render data.
Data fetching with GraphQL and Apollo Client.
Fetching data with class components.