Skip to content

Instantly share code, notes, and snippets.

@nelreina
Created September 14, 2016 21:09
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 nelreina/0af03947be904e57ff7a6ee2a9f4b487 to your computer and use it in GitHub Desktop.
Save nelreina/0af03947be904e57ff7a6ee2a9f4b487 to your computer and use it in GitHub Desktop.
Get Grid Row Columns/ React Utility function to for splitting data in row components
import React from 'react';
export const getGridRowColumns = (data, columns, Component, props ) => {
let retRows = [];
const rowCount = Math.ceil(data.length/ columns);
for (let i = 0; i < rowCount; i++) {
let rowData = [];
for (let x = 0; x < columns; x++) {
rowData.push( data[x + (i * columns)])
}
retRows.push(<Component key={i} data={rowData} {...props} />)
}
return retRows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment