Skip to content

Instantly share code, notes, and snippets.

@loganpowell
Created January 17, 2018 16:31
Show Gist options
  • Save loganpowell/81e6860ec1778b8d2f301ff45ffca044 to your computer and use it in GitHub Desktop.
Save loganpowell/81e6860ec1778b8d2f301ff45ffca044 to your computer and use it in GitHub Desktop.
When we want to separate data from its presentation so we can support multiple presentations easily.
// from: https://www.zhubert.com/blog/2016/02/05/react-composability-patterns/
const DataGetter = React.createClass({
render() {
const { children } = this.props
const data = [ 1,2,3,4,5 ]
return children(data)
}
})
const DataPresenter = React.createClass({
render() {
return (
<DataGetter>
{data =>
<ul>
{data.map((datum) => (
<li key={datum}>{datum}</li>
))}
</ul>
}
</DataGetter>
)
}
})
const App = React.createClass({
render() {
return (
<DataPresenter />
)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment