Last active
September 23, 2018 03:41
-
-
Save cserrano3/3a8eed88e65cdf2098c3697a346ae960 to your computer and use it in GitHub Desktop.
Generic List component made with Render Props
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 App = () => { | |
| <List | |
| render={ | |
| ({items}) => ( | |
| <ul> | |
| {items.map(item => { | |
| <li key={item.id}>{item.name}</li> | |
| })} | |
| </ul> | |
| ) | |
| } | |
| /> | |
| }; |
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
| 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