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

316
Views
React Select - Not loading data from an API

I'm trying to load data into dropbox(Combobox) from an API. Below are 2 React-Select dropdowns but it doesn't display(Show) any data in dropbox. I Also tried to loop through in the if below the let option but got nothing.

I tried Using reast_select Axios but had more errors than before. If I console log I get the data but however, it's just blank.

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 ClientDropdown

dropdown

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

0

You used clientData for both function name and variable name inside of that function. Also You are using spread operator when you use map like ...clientList.map((val). but you should use clientList.map((val) instead of ...clientList.map((val). I made correction in the below code. please check it.

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