Estoy tratando de cargar datos en Dropbox (Combobox) desde una API. A continuación hay 2 menús desplegables React-Select pero no muestra (Mostrar) ningún dato en el cuadro desplegable. También traté de recorrer el si debajo de la opción let pero no obtuve nada.
Intenté usar reast_select Axios pero tuve más errores que antes. Si registro la consola, obtengo los datos, pero sin embargo, está en blanco.
import React from 'react' import Select from 'react-select' import {useEffect,useState} from 'react' const options = [ { value: 'chocolate', label: 'Chocolate' }, { value: 'strawberry', label: 'Strawberry' }, { value: 'vanilla', label: 'Vanilla' } ] const ClientDropdown = () => { const [clientList,setClientList] = useState([]) //console.log(clientList) useEffect(() => { clientData(); },[]) const clientData = async() => { const response = await fetch("https://localhost:7168/TestData"); //console.log(response); const clientDataJson= await response.json(); //console.log(clientDataJson); setClientList(clientDataJson); } let option = [] if (clientList.values.length > 0) { clientList.values.forEach(client => { let roleDate = {} roleDate.value = client.studentid roleDate.label = client.sudentName option.push(roleDate) console.log('Im Here' + roleDate) }) } return ( <div> <Select options={option} /> <Select { ...clientList.map((val) => { return ( <options vlaue={val.studentid} label={val.sudentName}></options> ) }) } /> </div> ) } export default ClientDropdownUsó clientData para el nombre de la función y el nombre de la variable dentro de esa función. También está utilizando spread operator cuando usa un map como ...clientList.map((val) . Pero debe usar clientList.map((val) en lugar de ...clientList.map((val) . Hice la corrección en el siguiente código por favor verifíquelo.
import React from 'react' import Select from 'react-select' import {useEffect,useState} from 'react' const options = [ { value: 'chocolate', label: 'Chocolate' }, { value: 'strawberry', label: 'Strawberry' }, { value: 'vanilla', label: 'Vanilla' } ] const ClientDropdown = () => { const [clientList,setClientList] = useState([]) //console.log(clientList) useEffect(() => { clientData(); },[]) const clientData = async() => { const response = await fetch("https://localhost:7168/TestData"); //console.log(response); const data = await response.json(); //console.log(data); setClientList(data); } let option = [] if (clientList.values.length > 0) { clientList.values.forEach(client => { let roleDate = {} roleDate.value = client.studentid roleDate.label = client.sudentName option.push(roleDate) console.log('Im Here' + roleDate) }) } return ( <div> <Select options={option} /> <Select { clientList.map((val) => { return ( <options vlaue={val.studentid} label={val.sudentName}></options> ) }) } /> </div> ) } export default ClientDropdown