Skip to content

Instantly share code, notes, and snippets.

@tphdev
Last active November 5, 2016 18:35
Show Gist options
  • Save tphdev/d2fbaf31e1f80c241a414fc150413dd9 to your computer and use it in GitHub Desktop.
Save tphdev/d2fbaf31e1f80c241a414fc150413dd9 to your computer and use it in GitHub Desktop.
React Container Component
const DivContainerComponent = React.createClass({
render: function(){
return (
<div className={this.props.containerClassName || ""}>
{this.props.dataList.map((elData, i)=>{
return React.cloneElement(this.props.children, {data: elData, key: `${(new Date()).getTime()}-${i}`})
})}
</div>
)
}
})
const ListContainerComponent = React.createClass({
render: function(){
return (
<ul className={this.props.containerClassName || ""}>
{this.props.dataList.map((elData, i)=>{
return React.cloneElement(this.props.children, {data: elData, key: `${(new Date()).getTime()}-${i}`})
})}
</ul>
)
}
})
//Implementation
// let taskArray = [
// {task: 'wash cat', isDone: false},
// {task: 'brush dog', isDone: false},
// {task: 'brush dog', isDone: false},
//
// let TodoComponent = React.createClass({
// return: function(){
// return <li>{data.task} | {data.isDone.toString()} </li>
// }
// })
//
// ...
// <ContainerComponent containerClassName="todo-container" dataList={taskArray}>
// <TodoComponent/>
// </ContainerComponent>
//
module.exports = {
DivContainerComponent,
ListContainerComponent
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment