Reputation: 624
I have an array of reports with dates received via redux and want to group them by month and then by days like this:
January 2017 (header)
15th report 1
report 2 (also the 15th)
February 2018
1st report 3
4th report 4
I think I should sort the reports into a new array/object with month year and then days so that I can pass them to the react components without them needing to figure out if something is in the same year month or day. Or should I just sort and then evaluate it later on at the component level?
I was thinking of sorting and creating the new array in mapStateToProps of the container component for all of this. Is that the right place to do it?
Upvotes: 0
Views: 190
Reputation: 2600
I think mapStateToProps
is the best place to do this.
Earlier (in the reducer) breaks the no-side effects rule. Later (in the component) would have to be in the componentWillReceiveProps
lifecycle method - or you might have the temptation to put it in the render
or a method triggered by render
(which is the worst case scenario!).
The exception may be if this data is being consumed by multiple components. In this case you may want to re-think the data structure of the reducer.
Upvotes: 1