I want to use SectionList in React Native. Datas that SectionList needs to render looks like this:
sections=[
{
date: 'May 24 2019',
data: [
{
id:1,
msg: 'msg1',
date: 'May 24 2019'
},
{
id:2,
msg: 'msg2',
date: 'May 24 2019'
},
]},
{
date: 'May 25 2019',
data: [
{
id:3,
msg: 'msg1',
date: 'May 25 2019'
},
{
id:4,
msg: 'msg2',
date: 'May 25 2019'
},
]},
];
But data that I receive from server looks like this:
data:[
{
id:1,
msg: 'msg1',
date: 'May 24 2019'
},
{
id:2,
msg: 'msg2',
date: 'May 24 2019'
},
{
id:3,
msg: 'msg1',
date: 'May 25 2019'
},
{
id:4,
msg: 'msg1',
date: 'May 25 2019'
},
];
So how can I convert "data" to look like "sections". I appreciate your help. And sorry for my English.
{}in your output are wrong. They should be removed