Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

72
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda