Skip to content

Instantly share code, notes, and snippets.

@bherrero
Created April 27, 2017 21:50
Show Gist options
  • Save bherrero/2e2e7cce6a23d06cfaee45d59ff52719 to your computer and use it in GitHub Desktop.
Save bherrero/2e2e7cce6a23d06cfaee45d59ff52719 to your computer and use it in GitHub Desktop.
React Native - prepare SectionList's array with lodash
// maps it's an array of objects
// groupBy to extract section headers
let dataSource = _.groupBy(maps, o => o.name);
// reduce to generate new array
dataSource = _.reduce(dataSource, (acc, next, index) => {
acc.push({
key: index,
data: next
});
return acc;
}, []);
return dataSource;
@mrkp
Copy link

mrkp commented Aug 27, 2021

You're a legend!

@manchoudhary
Copy link

yes great answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment