Created
June 18, 2016 06:26
-
-
Save markerikson/22b19130cce7420a37a1381b6404e96f to your computer and use it in GitHub Desktop.
React render logic split approaches
This file contains 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
class ChildComponent = (props) => <div>{props.name}</div>; | |
class MyComponent extends Component { | |
renderItem(item, index) { | |
return <ChildComponent key={index} name={item.name} /> | |
} | |
render() { | |
const {list1, list2, list3} = this.props; | |
const renderedFirstList = list1.map(this.renderItem); | |
const renderedSecondList = list2.map(item => <ChildComponent key={item.id} name={item.name} />); | |
const renderedThirdList = list3.map(item => { | |
const updatedName = item.name + "testing"; | |
return <ChildComponent key={item.id} name={updatedName} /> | |
}); | |
return ( | |
<div> | |
{renderedFirstList} | |
{renderedSecondList} | |
{renderedThirdList} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment