1

is there a way to display a default message when the date passed to Moment is invalid?

<Moment fromNow>not-a-date</Moment>

I´m getting Invalid Date.

handsome
  • 2,093
  • 4
  • 34
  • 62

2 Answers2

2

Tage a look Check if date is a valid one

you should not use moment as jsx element, it is an normal class.

2
getDate() {
    if (!this.props.date || check for invalid date) {
        return "Alternative Message on Invalid date"
    }

    return  <Moment fromNow>{this.props.date}</Moment>
}

render() {
    return this.getDate()
}