Hobaxo
Hobaxo

Reputation: 31

How do I set the value of an ant DatePicker in React (using react-moment)?

I need to convert this:

{object.startDate !== null ? <Moment format="MM/DD/YYYY" date={object.startDate}/> : "-----------"}

into something like this:

<DatePicker value={Moment format="MM/DD/YYYY" date={object.startDate}} />

How do I correctly do this?

Upvotes: 0

Views: 1019

Answers (2)

Hobaxo
Hobaxo

Reputation: 31

After installing moment (as stated by Sheldon), this is how it tweaked it to make it work:

<DatePicker value={moment(object.startDate, 'MM/DD/YYYY')} />

Upvotes: 0

Sheldon Oliveira
Sheldon Oliveira

Reputation: 1005

To use react-moment it is a must to have moment installed.

From the docs:

"Use npm to install react-moment along with its peer dependency, moment" https://www.npmjs.com/package/react-moment

import moment from 'moment'
...
<DatePicker value={moment(object.startDate).format('MM/DD/YYYY')} />
...

Upvotes: 1

Related Questions