When fetching tasks from the API, I receive both active and completed tasks. My goal is to restructure this data to be compatible with SectionList in React-Native, organizing tasks based on their creation date (dataCadastro) so that they can be separated by day. You can refer to the documentation here: https://reactnative.dev/docs/sectionlist
{
active: [
{
id: 1,
dataCadastro: '2020-06-15T14:33:45.4807609+00:00',
status: 1,
description: '',
},
{
id: 2,
dataCadastro: '2020-06-15T15:33:45.4807609+00:00',
status: 1,
description: '',
},
],
completed: [
{
id: 3,
dataCadastro: '2020-05-19T14:33:45.4807609+00:00',
status: 1,
description: '',
},
{
id: 4,
dataCadastro: '2020-05-19T15:33:45.4807609+00:00',
status: 1,
description: '',
}
]
}
The desired outcome would look like this:
const dataTest = [
{
title: '2020-06-15', // All tasks for the 15th of June.
data: [
{
id: 1,
dataCadastro: '2020-06-15T14:33:45.4807609+00:00',
status: 1,
description: '',
},
{
id: 2,
dataCadastro: '2020-06-15T15:33:45.4807609+00:00',
status: 1,
description: '',
}
],
}, {...}
];