Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda