Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active September 7, 2018 20:59
Show Gist options
  • Save ajcrites/cf6fb018e3d7a3cf92adb0b0044ed409 to your computer and use it in GitHub Desktop.
Save ajcrites/cf6fb018e3d7a3cf92adb0b0044ed409 to your computer and use it in GitHub Desktop.
// 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>
);
}
}
// 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