Clone moment js object

There's a method to clone a moment object:

const yearBefore = this.state.startDate.clone().subtract(1, 'years');

It would also be a better idea to store a serialisable representation of the date in your component state, such as the result of calling .valueOf() on either a Date or a Moment, either of which returns the number of milliseconds since the UNIX epoch.


It's also possible to copy a moment object through it's constructor. Like so

const firstMoment = moment("2020-08-18");
const clone = moment(firstMoment);

moment.js has its own api for cloning moment object.

var copy = momentObj.clone();

And I agree on storing dates serialize representation instead of Object in store.