I have my data in this format:
const INITIAL_STATE = {
expenses: {
byId: {
k948zpnp: {
id: 'k948zpnp',
category: 'other',
description: 'book',
amount: '25',
timeSpent: '2.5',
time: '2020-04-21'
}
},
allIds: ['k948zpnp']
}
}
What I want to do is render Component that contains date - so all my child components (SingleItem) that have the same time are grouped in it.
<ExpensesByDay date={time)>
<SingleItem restOfData={...} />
</ExpensesByDay>
I'm grouping my data by the time property and the final object:
budgetByDay = {
2020-04-11: (4) [{…}, {…}, {…}, {…}],
2020-04-20: [{…}],
2020-04-21: (2) [{…}, {…}]
}
Then I make and an array of all the dates and do this:
{datesArray.map(date =>
budgetByday[date].map(item => (
<DailyBudget date={date}>
<SingleItem
keyAndRest={...}
/>
</DailyBudget>
))
)}
But this won't work. I'm thinking that my approach might be incorrect from the beginning and I might not need my expenses grouped by date. How would you approach this task?