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

69
Visualizações
Storage list of contacts by first letter index

I'm making a contact list ordered alphabetically, the way that I'm currently storing is inside an object like this:

{
  "&": [
    {
      "key": "20444358",
      "initials": "@#",
      "name": "@name #"
    },
    {
      "key": "20444669",
      "initials": "@@",
      "name": "@ @"
    }
  ],
  "#": [
    {
      "key": "4419686",
      "initials": "1",
      "name": "1075621114"
    },
    {
      "key": "41604990",
      "initials": "12",
      "name": "123 Test 23"
    },
    {
      "key": "32783347",
      "initials": "2",
      "name": "232323"
    }
  ],
  "A": [
    {
      "key": "20444317",
      "initials": "AJ",
      "name": "Àbdon Jua"
    },
    {
      "key": "20444454",
      "initials": "AA",
      "name": "Abraão Moura"
    }
  ]
}

I'm facing two problems at the moment:

  1. When I fetch a new page of contacts and need to merge them with the current object I'm doing like this: contacts = {...contacts, ...newContacts}
  2. I'm rendering them on a FlatList, and having a hard time getting the Index.

This is my fetch:

if (response.data !== []) {
  for (let i = 0; i < response.data.length; i++) {
    let indexInitial = getIndexInitial(response.data[i].name)
    if (!(indexInitial in newContacts)) {
      newContacts[indexInitial] = [{
        key: response.data[i].id.toString(),
        initials: getInitials(response.data[i].name),
        name: response.data[i].name
      }]
    } else {
      newContacts[indexInitial].push({
        key: response.data[i].id.toString(),
        initials: getInitials(response.data[i].name),
        name: response.data[i].name
      })
    }
  }
  pushContacts(newContacts);
  page.current = currentPage + 1;
} else {
  setEndOfTheList(true)
}
about 4 years ago · Juan Pablo Isaza
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