Skip to content

Instantly share code, notes, and snippets.

@mandiwise
Last active May 22, 2018 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandiwise/bda1b921e12817373560d626970d630d to your computer and use it in GitHub Desktop.
Save mandiwise/bda1b921e12817373560d626970d630d to your computer and use it in GitHub Desktop.
Function to help format data fetched from the R10 Graphcool API for a React Native SectionList.
// Helper to format GraphQL data into section list data
export const formatSessionData = sessions => {
return sessions
.reduce((acc, curr) => {
const timeExists = acc.find(section => section.title === curr.startTime);
timeExists
? timeExists.data.push(curr)
: acc.push({ title: curr.startTime, data: [curr] });
return acc;
}, [])
.sort((a, b) => a.title - b.title);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment