Created
January 17, 2018 16:31
-
-
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.
This file contains 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
// 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