Skip to content

Instantly share code, notes, and snippets.

@albertorestifo
Created April 26, 2017 10:31
Show Gist options
  • Save albertorestifo/56e6cc687cbf584cdf8abea89cae6e28 to your computer and use it in GitHub Desktop.
Save albertorestifo/56e6cc687cbf584cdf8abea89cae6e28 to your computer and use it in GitHub Desktop.
import React from 'react';
function Cell({ children }) {
return <td>{children}</td>;
}
function Row({ children }) {
return (
<tr>
{React.Children.map(children, (el) => {
if (el.type === Cell) return el;
return <td>{el}</td>;
})}
</tr>
);
}
function Grid({ children }) {
return (
<table>
<tbody>
{React.Children.map(children, (el) => {
if (!el) return;
if (el.type === Row) return el;
if (el.type === Cell) {
return <tr>{el}</tr>;
}
return (
<tr>
<td>{el}</td>
</tr>
);
})}
</tbody>
</table>
);
}
Grid.Row = Row;
Grid.Cell = Cell;
export default Grid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment