Reputation: 2422
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.
Upvotes: 1
Views: 1862
Reputation: 1
getDate() {
if (!this.props.date || this.props.date===" " || check for invalid date criteria)
{
return "Alternative Message on Invalid date"
}
return <Moment fromNow>{this.props.date}</Moment>
}
render() {
return this.getDate()
}
Upvotes: 0
Reputation: 147
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()
}
Upvotes: 2
Reputation: 147
Tage a look Check if date is a valid one
you should not use moment as jsx element, it is an normal class.
Upvotes: 2