Shashika Virajh
Shashika Virajh

Reputation: 9487

Display two dates in react

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

Answers (1)

T.J. Crowder
T.J. Crowder

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

Related Questions