Created
April 27, 2017 21:50
-
-
Save bherrero/2e2e7cce6a23d06cfaee45d59ff52719 to your computer and use it in GitHub Desktop.
React Native - prepare SectionList's array with lodash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're a legend!