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

153
Views
How to render a dynamic drop down in react?

I'm trying to render a drop down menu using an array in the state of my react project. It looks like this:

export default class MyTable extends React.Component {
     constructor(props){
          super(props);
          this.state= { list:[1,2,3,4]}
     }

     render() {
          return(
               <div>
                    <select>
                         {this.state.list.map(i => {
                              <option key={i}>{i}</option>
                         })}
                    </select>
               </div>
          );

     }


}

the dropdown is blank though and I can't understand why it's not working???

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

0

You are not returning anything from .map loop.

Modified code:

export default class MyTable extends React.Component {
  constructor(props) {
    super(props);
    this.state = { list: [1, 2, 3, 4] };
  }

  render() {
    return (
      <div>
        <select>
          {this.state.list.map((i) => {
            // <option key={i}>{i}</option>; Before
            return <option key={i}>{i}</option>; // Return value here
          })}
        </select>
      </div>
    );
  }
}
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!