简体   繁体   English

是否可以将js对象存储在redux react中?

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

In redux state tree How do we store dates ? 在redux状态树中,我们如何存储日期?

  1. store moment objects in redux 将矩对象存储在redux中
  2. store js date objects in redux 将js日期对象存储在redux中
  3. convert to ISO 8601 string and then store 转换为ISO 8601字符串然后存储
  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. 在当前项目中,我们将其存储为矩对象,但仍不确定这是否正确。

When dealing with dates I'd prefer to store as a unix format or ISO string. 在处理日期时,我更喜欢以unix格式或ISO字符串存储。 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. 使用重新选择,您可以创建一个矩实例来访问日期值。

i would just format it to epoch or the ISO string you mentioned and store it, and if its needed again convert it back to whatever you need. 我只是将其格式化为您提到的时代或ISO字符串并存储,如果需要,可以再次将其转换回您需要的任何格式。 its pretty redundant to store an object over and over 一遍又一遍地存储对象非常多余

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM