I am new to React and Gatsby and I want to condition a css rule based upon a value I am retrieving from my backend. This is my current frontend code:
{course.map(item => {
return (
<div key={item.id} className="job-desc">
<h4>Kurs:</h4>
<h4>{item.title}</h4>
<span>{item.credits} poäng</span>
<span>startdatum: {item.start}</span>
<span>slutdatum: {item.end}</span>
</div>
)
})}
What I would like to achieve is to set the class name for h4 tag from the current class job-desc h4 rule to .educationsOver if the date value in item.end is older then current date.
Instead of:
<h4>{item.title}</h4>
So maybe something like:
const current = new Date();
<h4 className={`current.getDate() > ${item.end} ? "educationsOver" : "job-desc"`}>{item.title}</h4>
But this is the generated HTML code for the first occurrence of the map loop:
<h4 class="current.getDate() > 2021-02-05 ? "educationsOver" :"job-desc"">Kommunikation</h4>
2021-02-05 being the first value of {item.end}
What am I missing in my code?