Skip to content

Instantly share code, notes, and snippets.

@cserrano3
Last active September 23, 2018 03:41
Show Gist options
  • Select an option

  • Save cserrano3/3a8eed88e65cdf2098c3697a346ae960 to your computer and use it in GitHub Desktop.

Select an option

Save cserrano3/3a8eed88e65cdf2098c3697a346ae960 to your computer and use it in GitHub Desktop.
Generic List component made with Render Props
const App = () => {
<List
render={
({items}) => (
<ul>
{items.map(item => {
<li key={item.id}>{item.name}</li>
})}
</ul>
)
}
/>
};
export default class List extends React.Component {
constructor(props) {
super(props);
this.state = {
items: []
};
}
componentDidMount() {
this.setState({items: source.getItems()});
}
render() {
return this.props.render(this.state);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment