Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DarkoTrpevski/4896ae27107b150a113aaaf23b5a626d to your computer and use it in GitHub Desktop.
Save DarkoTrpevski/4896ae27107b150a113aaaf23b5a626d to your computer and use it in GitHub Desktop.
//*Example
//Where ( listOfItems ) is an array of items
<List items={listOfItems} dir="vertical">
{(listOfItem) => (
<dl>
<dt>Name</dt>
<dd>{listOfItem.name}</dd>
<dt>Created</dt>
<dd>{listOfItem.since}</dd>
<dt>Author</dt>
<dd>{listOfItem.author}</dd>
</dl>
)}
</List>
import React from 'react';
interface Props<T> {
children: (item: T) => React.ReactNode,
items: T[],
dir?: 'horizontal' | 'vertical',
dividers?: boolean,
windowing?: boolean
}
interface IdObj {
id: string | number
}
const List = <T extends IdObj>({ children, dir, dividers, items, windowing }: Props<T>) => {
return (
<div>
{items.map((item, idx) => (
<div key={idx} className="item">
{children(item)}
</div>
))}
</div>
)
}
export default List;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment