React time ago not getting date

I’m using react-timeago package, i just need to get the data from a parent component by props, when i put the data in the date prop of TimeAgo i get nothing. is not getting the data in the TimeAgo component, i have tried but in vain. the code below is in the same component

// this returns for ex 'Published 2 days ago'
<div>Published {}</div>
// this returns only 'Published'
<div>Published <TimeAgo date={} formatter={formatter}/></div>


Your return a literal string that cannot be directly converted into a date object or date string, firstly you’ll need to convert it into a standard format and then pass it to the props. Before the return block add this code.

var calDate = stringToDate()

function stringToDate(){
 let cDate = new Date();
cDate.setDate(cDate.getDate() - parseInt(; //Get the integer part of X days ago, e.g return the integer 2 from 2 days ago and then subtract 2 days from current date.
return cDate

Update the value passed to prop to the value we calculated above.

// this returns for ex 'Published 2 days ago'
<div>Published {}</div>
// this returns only 'Published'
<div>Published <TimeAgo date={calDate} formatter={formatter}/></div>