JS3
JS3

Reputation: 1829

Showing an Invalid Date, how can I fix this?

If the data does not exist in the database, there's no error but it will just display an Invalid Date on the screen. How can I do this where if the data does not exist in the database, then it will just be empty.

 First Item:
              {new Date(
                user.items?.firstDateseconds * 1000
              ).toDateString()}

Upvotes: 0

Views: 89

Answers (1)

Ryan Le
Ryan Le

Reputation: 8412

You could check if it's not empty before using new Date()

Something like this:

First Item: {
   user.items?.firstDateseconds
      ? new Date(user.items.firstDateseconds * 1000).toDateString()
      : '';
}

Upvotes: 3

Related Questions