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

77
Views
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 answers
Answer question

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 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!