Skip to content

Instantly share code, notes, and snippets.

@jake-daniels
Last active May 4, 2018 15:01
Show Gist options
  • Save jake-daniels/6f1cc1789463a2281bdc52647e58fb49 to your computer and use it in GitHub Desktop.
Save jake-daniels/6f1cc1789463a2281bdc52647e58fb49 to your computer and use it in GitHub Desktop.
Table component with nested components.
class Table extends React.Component {
Head = () => {
return (
<div className='head'>
</div>
)
}
Body = () => {
return (
<div className='body'>
{this.props.items.map((item, index) =>
<this.Row key={index} data={item}/>
)}
</div>
)
}
Row = ({data}) => {
return (
<div className='row'>
<div className='column'>
{data.someProperty}
</div>
{/* ...more columns */}
</div>
)
}
render () {
return (
<div className='table'>
<this.Head />
<this.Body />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment