Reputation: 9487
I want to display two dates in my react application. It should be displayed as Date1 - Date2. Here is the code.
export const formatFromToDates = (fromDate, toDate) => {
return (
<Moment format='YYYY/MM/DD'>{fromDate}</Moment> -
toDate === null ? ' Now' : <Moment format='YYYY/MM/DD'>{toDate}</Moment>
);
}
But is only displays the second date. How should I do this?
Upvotes: 0
Views: 45
Reputation: 1075567
You've forgotten to put {}
around your JSX expression for toDate
:
export const formatFromToDates = (fromDate, toDate) => {
return (
<Moment format='YYYY/MM/DD'>{fromDate}</Moment> -
{toDate === null ? ' Now' : <Moment format='YYYY/MM/DD'>{toDate}</Moment>}
// -----^------------------------------------------------------------------------^
);
};
Upvotes: 2