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

115
Views
populate select element from state in react

New react developer here, trying to learn by coding, here I am stuck with simple select element, I have select element and inside it using map to populate options, i'm also consoling logging my data inside map and getting '50 getting data FUNDING_ACCOUNT'.

what I want to achieve is: a select element which user clicks and gets 'data.name' as dropdown, where is my mistake?

English is not my mother language so there could be mistakes.

i'm using fetch to populate 'setUpdateSelect'

My code:

  const [updateSelect, setUpdateSelect] = useState([]);


<select>
          {updateSelect.map((data) => {
            console.log("getting data", data.name);
            <option key={data.name} value={data.name}>
              {data.name}
            </option>;
          })}
        </select>

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

0

With a map function, it should return something. In your map function it doesn't return anything.

Modified code

{updateSelect.map((data) => {
   console.log("getting data", data.name);
    return (
      <option key={data.name} value={data.name}>
        {data.name}
      </option>
    );
})}

This should now work properly.

Thanks,

Arjis Chakraborty.

about 4 years ago · Juan Pablo Isaza Report

0

const [updateSelect, setUpdateSelect] = useState([]);

<select>
    {updateSelect.map((data) => {
        return( console.log("getting data", data.name);
                <option key={data.name} value={data.name}>
                  {data.name}
                </option>;)
               
     })}
</select>
about 4 years ago · Juan Pablo Isaza Report

0

For rerendering, you can use like this;

const [updateSelect, setUpdateSelect] = useState([]);
const [loading, setLoading] = useState(false);


useEffect(() => {
 setLoading(true);
 setUpdateSelect(yourdata);
 setLoading(false);

},[yourdata])


return !loading ? (
<select>
 updateSelect.map((data, index) => (
  <option key={index} value={data.name}> 
   {data.name}
  </option>
 )
</select>
) : null; 
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!