Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to store moment js object in redux react?

In redux state tree How do we store dates ?

  1. store moment objects in redux
  2. store js date objects in redux
  3. convert to ISO 8601 string and then store
  4. Something better than these

ie,

state={
    fromTime: action.payload.fromTimeMoment,
    dateTime: action.payload.dateTimeEs6,
    toTime: action.payload.toTimeAsString,
}

In our current project we have stored it as moment objects, still not sure if that was the right thing to do.

like image 313
sdb Avatar asked Nov 08 '22 06:11

sdb


1 Answers

When dealing with dates I'd prefer to store as a unix format or ISO string. The reason for this is because I might want to save the state to the local storage for speed things up for second time users.

Keeping instances of other classes (or in this case moment) in the store, you might find some problems while serializing the state.

Using reselect you can create a moment instance to access the date value.

like image 66
Crysfel Avatar answered Nov 14 '22 23:11

Crysfel