Skip to content

Instantly share code, notes, and snippets.

@xemasiv
Last active May 21, 2018 19:00
Show Gist options
  • Save xemasiv/ef32336553942662d3ee2300e81fe34b to your computer and use it in GitHub Desktop.
Save xemasiv/ef32336553942662d3ee2300e81fe34b to your computer and use it in GitHub Desktop.
ListComponentMap
const ListComponentMap = L => C => M => Ch => (<div>{
( typeof L === 'number' ?
((L) => {
let arr = new Array(L);
for (let k = 0; k < arr.length; k++) (arr[k] = k + 1);
return arr; })(L)
: L )
.map((i, n) =>
<C key={n} {...typeof M === 'function' ? M(i, n) : M }>
{typeof Ch === 'function' ? Ch(i, n) : Ch}
</C>)
} </div>);
/*
ACCEPTED VALUES:
{
ListComponentMap
(fruits) // array list
(HH) // react component
( (item, index) => ({ name: item }) ) // props from function
((i, n) => <H name={n} />) // children from function
}
{
ListComponentMap
(number) // number
(HH) // react component
( { name: "item" } ) // props from object
(<H name="josh"/>) // children from component
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment