Im trying to add a "New" badge example: <IonBadge color="primary">New</IonBadge>
in the <IonCardHeader>
if the (job.createdAt)
equals "today".
How would you recommend I go about this?
The date as in, the current date, not a string.
Im using Ionic React v4.
Card Function below.
Thanks so much for your insights!!
function renderJobList(job) {
return [{}].concat(job).map((job, i) =>
i !== 0 ? (
<LinkContainer key={job.jobId} to={`/jobinfo/${job.jobId}`}>
<IonItemGroup>
<IonCard>
<IonCardHeader>
<IonCardSubtitle><b>{(job.packageSelected)}</b></IonCardSubtitle>
<IonCardTitle><h3>{(job.streetAddress)} {(job.city)} {(job.state)} {(job.zipCode)}</h3></IonCardTitle>
</IonCardHeader>
<IonCardContent>
<p><b> Start Date: </b> {parseISO(job.startDate).toLocaleString()}</p>
<p><b> Created At: </b> {new Date(job.createdAt).toLocaleString()}</p>
</IonCardContent>
</IonCard>
</IonItemGroup>
</LinkContainer>
Try add this:
let today = new Date(new Date().getFullYear(),new Date().getMonth() , new Date().getDate())
and then use:
<IonCardHeader>{job.createdAt == today ? (<IonBadge color="primary">New</IonBadge>) : null}</IonCardHeader>