Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created April 14, 2020 15:04
Show Gist options
  • Save jsmanifest/5049758cccb9c0386933e1b005a514ef to your computer and use it in GitHub Desktop.
Save jsmanifest/5049758cccb9c0386933e1b005a514ef to your computer and use it in GitHub Desktop.
function ListComponent({
label,
items = [],
collapsed,
toggle,
limit,
total,
renderListItem,
}) {
return (
<ul>
<p>{label}</p>
{items.map((member) =>
renderListItem ? (
<React.Fragment key={member}>{renderListItem({ collapsed, toggle, member )}</React.Fragment>
) : (
<ListItem key={member}>{member}</ListItem>
),
)}
{total > limit && (
<ListItem className='expand'>
<button type='button' onClick={toggle}>
{collapsed ? 'Expand' : 'Collapse'}
</button>
</ListItem>
)}
</ul>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment