Last active
November 5, 2016 18:35
-
-
Save tphdev/d2fbaf31e1f80c241a414fc150413dd9 to your computer and use it in GitHub Desktop.
React Container Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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