Last active
September 7, 2018 20:59
-
-
Save ajcrites/cf6fb018e3d7a3cf92adb0b0044ed409 to your computer and use it in GitHub Desktop.
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
// Example | |
export class RenderMethodComponent extends React.Component { | |
renderList = () => ( | |
<View>{this.props.items.map(() => ( | |
<Deeply><Nested><Views> | |
</Views></Nested></Deeply> | |
)}</View> | |
); | |
renderAddButton = () => ( | |
<View><Button onPress={this.onButtonPress}>Add</Button></View> | |
) | |
render() { | |
return ( | |
<View> | |
{this.props.items.length && this.renderList()} | |
{this.props.addButton && this.renderAddButton()} | |
</View> | |
); | |
} | |
} |
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
// Better Example | |
const ListItem: React.SFC = () => ( | |
<Deeply><Nested><Views> | |
</Views></Nested></Deeply> | |
); | |
const List: React.SFC<{ items }> => items.map(() => <ListItem />); | |
const AddButton: React.SFC<{ onButtonPress }> = ( | |
<View><Button onPress={onButtonPress}>Add</Button></View> | |
); | |
export class RenderComponentsComponent extends React.Component { | |
render() { | |
return ( | |
<View> | |
{this.props.items.length && <List items={this.props.items} />} | |
{this.props.addButton && <AddButton onButtonPress={this.onButtonPress} />} | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment