在哪里修改 redux 中反应组件的数据?

Where to modify data for a react component in redux?

我有一系列报告,其中包含通过 redux 收到的日期,我想按月然后按天对它们进行分组,如下所示:

January 2017 (header)
15th report 1
     report 2 (also the 15th)
February 2018
1st report 3
4th report 4

我想我应该将报告分类为一个新的 array/object,先是年月,然后是天,这样我就可以将它们传递给反应组件,而不需要它们弄清楚是否有东西在同一年月或一天。或者我应该先排序然后再在组件级别对其进行评估?

我正在考虑为所有这些在容器组件的 mapStateToProps 中排序和创建新数组。这是正确的地方吗?

我认为 mapStateToProps 是最好的地方。

早些时候(在减速器中)打破了无副作用规则。稍后(在组件中)必须在 componentWillReceiveProps 生命周期方法中 - 或者您可能会想把它放在 render 或由 render 触发的方法中(这是最坏的情况!)。

如果多个组件正在使用此数据,则可能会出现异常。这种情况下你可能要重新考虑reducer的数据结构了。