Skip to content

Instantly share code, notes, and snippets.

@joemaddalone
Last active January 20, 2019 16:47
Show Gist options
  • Save joemaddalone/d0f422f57e02ccdfc5b485b7553e4dc3 to your computer and use it in GitHub Desktop.
Save joemaddalone/d0f422f57e02ccdfc5b485b7553e4dc3 to your computer and use it in GitHub Desktop.
Map Component
const Map = ({list, key, children}) => {
const child = React.Children.only(children);
const Item = child.type;
return list.map((item, index) => {
const keyed = Object.assign({key: item[key] || index}, item)
return React.createElement(Item, keyed);
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment