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

71
Visualizações
Sorting an array by the children attribute in react

in my app, I have a map of an array that returns a div with a data-date attribute like so:

Note I cannot sort the array here as I don't have any dates to compare them with, only the ID of the element


const mappedArray = array.map(el=>{
  return (
   <DivComponent el={el} />
  )
})

Inside the DivComponent, I make a fetch to firebase where I get the info of each div along with a timestamp

const DivComponent = (props) => {
 const info = useGetInfo(props.el.id) 
 return (
  <div data-data={info.date.toDate()}>Some content</div>
 )
}

Given these conditions, is it possible to sort the array above given that each children have an assigned date ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

is it okay to change the props on DivComponent and move the useGetInfo outside?

const mappedArray = array.map(el=>useGetInfo(el.id))
.sort((info1,info2)=>info1.date.toDate()>info2.date.toDate()?1:-1)
.map(info=>{
 return (
    <DivComponent info={info} />
  )
})
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