Created
May 28, 2018 06:24
-
-
Save cyan33/963ea414262f0ae39eef5cddb591db55 to your computer and use it in GitHub Desktop.
Usage of react 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
// This is a stupid example of using render props when I was | |
// reading the doc of React.children | |
const React = require('react'); | |
class CountSiblings extends React.Component { | |
render() { | |
const {children} = this.props; | |
return children( | |
React.Children.count(children), | |
); | |
} | |
} | |
// usage | |
<CountSiblings> | |
{count => ( | |
<> | |
<Child1 count={count} /> | |
<Child2 count={count} /> | |
<Child3 count={count} /> | |
</> | |
)} | |
</CountSiblings> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment