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

299
Views
Drop down button is showing a blank row. How Do I fix the issue?

So my issue is that I have a drop-down menu and the items are a bit strange. The first row looks blank and the data that I have looks like this.

users data

I know the first user has a username: null and that is probably why the blank is showing but in the frontend I want to change the username of user of index 0 to always say "Myself" whether it is null or not. How Do I do modify its value?

This is how the drop-down looks like

drop-down

  async componentDidMount() {
    const ep = `${process.env.REACT_APP_API}/partners/roles`;
    const users = await axios.get(ep);
    
    if (users.data.success) {
      this.setState({
        users: users.data.data.users.filter(f => !f.isArchived)
      });
    }
    console.log("Users", users)
    if (this.props.item) {
      this.setState({
        id: this.props.item.id,
        description: this.props.item.description,
        due: this.props.item.due,
        priority: this.props.item.priority,
        assigned: this.props.item.assigned
      });
    }
  }

This is where the drop-down items are being generated

  <select
    name="assigned"
    id="assignedto"
    type="text"
    className="form-control"
    style={{ width: "70%" }}
    onChange={e => {
      this.setState({
        assigned: e.target.value
      });
    }}
  >
  <option value="">Myself</option>
    {this.state.users.map(e => (
      <option value={e.id} key={e.id}>
        {e.username}
      </option>
    ))}
  </select>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Maybe use the index?

<select
    name="assigned"
    id="assignedto"
    type="text"
    className="form-control"
    style={{ width: "70%" }}
    onChange={e => {
      this.setState({
        assigned: e.target.value
      });
    }}
  >
  <option value="">Myself</option>
    {this.state.users.map(e => (
      <option value={e.id} key={e.id} index>
index == 0 ? 'Myself' : {e.username} 
      </option>
    ))}
  </select>
about 4 years ago · Juan Pablo Isaza Report

0

You can add a check while rendering like this:

<option value={e.id} key={e.id}> {e.username ? e.username : 'Myself'} </option>

Usually the right approach is to clean your data when you're setting the state:

users.forEach((u => { if (!u.name) { u.name = 'Myself'; } }));
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!