0

i have code this and i want sort newst date to the oldest date. Than you my friend.

enter image description here

const renderDataNews = (data) => {
    if (context.locale === 'en') { 
    return (
    <> 
      {data.map((news, index) => {
          return (
            <Col key={index} lg='4' md='6' sm='6' xs='12'>
            <Card>
            <CardBody> 
            <CardTitle className='text-right'>{moment(news.date).format('YYYY-MM-DD')}</CardTitle>
                    <li key={index}>{news.title_en}</li>
                    <p>{news.des_en}</p>
            </CardBody>
            </Card>
            </Col>
          )
        })}
   </>
    )
Trin
  • 1

1 Answers1

1

Perhaps using a methodology like explained here : How to sort an object array by date property?

data.sort((a,b) => new Date(b.date) - new Date(a.date)).map( /* your mapping code */)
David Kerr
  • 1,058
  • 1
  • 8
  • 12